WIP: Fix pycodestyle errors (#653)

* Fix pycodestyle errors

W503 is condracting PEP-8 and was added to the default ignore list by
pycodestyle developers

* Use setup.cfg for pycodestyle ignore parameters

Addresses #651 (kind of). Appending ignores to the default list prevents
us from getting warnings that we don't care about.

* W503 is not in the default ignore list in 2.4.0
This commit is contained in:
Егор 2018-08-06 16:29:19 +03:00 committed by enkore
parent 0dad095c07
commit 0d7156b5b1
11 changed files with 28 additions and 25 deletions

View File

@ -9,7 +9,7 @@ BUILD=${1:-ci-build}
rm -rf ${BUILD}/ rm -rf ${BUILD}/
mkdir -p $BUILD mkdir -p $BUILD
python3 -mpycodestyle --ignore E501,E741,E305,E722 i3pystatus tests python3 -mpycodestyle i3pystatus tests
# Check that the setup.py script works # Check that the setup.py script works
rm -rf ${BUILD}/test-install ${BUILD}/test-install-bin rm -rf ${BUILD}/test-install ${BUILD}/test-install-bin

View File

@ -13,9 +13,9 @@ class ClassFinder:
def predicate_factory(self, module): def predicate_factory(self, module):
def predicate(obj): def predicate(obj):
return ( return (
inspect.isclass(obj) and inspect.isclass(obj)
issubclass(obj, self.baseclass) and and issubclass(obj, self.baseclass)
obj.__module__ == module.__name__ and obj.__module__ == module.__name__
) )
return predicate return predicate

View File

@ -271,7 +271,7 @@ def formatp(string, **kwargs):
return subtree return subtree
def merge_tree(items): def merge_tree(items):
return "".join(flatten(items)).replace("\]", "]").replace("\[", "[") return "".join(flatten(items)).replace(r"\]", "]").replace(r"\[", "[")
stack = build_stack(string) stack = build_stack(string)
tree = build_tree(stack, 0) tree = build_tree(stack, 0)

View File

@ -171,8 +171,8 @@ cleartext to the server.)"),
full_text = formatp(self.format, **fdict).strip() full_text = formatp(self.format, **fdict).strip()
full_text_len = len(full_text) full_text_len = len(full_text)
if full_text_len > self.max_len and self.max_len > 0: if full_text_len > self.max_len and self.max_len > 0:
shrink = floor((self.max_len - full_text_len) / shrink = floor((self.max_len - full_text_len)
len(self.truncate_fields)) - 1 / len(self.truncate_fields)) - 1
for key in self.truncate_fields: for key in self.truncate_fields:
fdict[key] = fdict[key][:shrink] + "" fdict[key] = fdict[key][:shrink] + ""

View File

@ -353,8 +353,8 @@ class Network(IntervalModule, ColorRangeModule):
def init(self): def init(self):
# Don't require importing basiciw unless using the functionality it offers. # Don't require importing basiciw unless using the functionality it offers.
if any(s in self.format_down or s in self.format_up or if any(s in self.format_down or s in self.format_up
any(s in f for f in self.format_active_up.values()) or any(s in f for f in self.format_active_up.values())
for s in ['essid', 'freq', 'quality', 'quality_bar']): for s in ['essid', 'freq', 'quality', 'quality_bar']):
get_wifi_info = True get_wifi_info = True
else: else:

View File

@ -160,10 +160,10 @@ https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
"title": currentsong.get("xesam:title", ""), "title": currentsong.get("xesam:title", ""),
"album": currentsong.get("xesam:album", ""), "album": currentsong.get("xesam:album", ""),
"artist": ", ".join(currentsong.get("xesam:artist", "")), "artist": ", ".join(currentsong.get("xesam:artist", "")),
"song_length": TimeWrapper((currentsong.get("mpris:length") or "song_length": TimeWrapper(
0) / 1000 ** 2), (currentsong.get("mpris:length") or 0) / 1000 ** 2),
"song_elapsed": TimeWrapper((get_prop("Position") or 0) / "song_elapsed": TimeWrapper(
1000 ** 2), (get_prop("Position") or 0) / 1000 ** 2),
"filename": "", "filename": "",
} }

View File

@ -210,7 +210,7 @@ class PulseAudio(Module, ColorRangeModule):
if self.move_sink_inputs: if self.move_sink_inputs:
sink_inputs = subprocess.check_output("pacmd list-sink-inputs".split(), sink_inputs = subprocess.check_output("pacmd list-sink-inputs".split(),
universal_newlines=True) universal_newlines=True)
for input_index in re.findall('index:\s+(\d+)', sink_inputs): for input_index in re.findall(r'index:\s+(\d+)', sink_inputs):
command = "pacmd move-sink-input {} {}".format(input_index, next_sink) command = "pacmd move-sink-input {} {}".format(input_index, next_sink)
# Not all applications can be moved and pulseaudio, and when # Not all applications can be moved and pulseaudio, and when

View File

@ -75,9 +75,9 @@ class Reddit(IntervalModule):
_permalink = "" _permalink = ""
_url = "" _url = ""
subreddit_pattern = re.compile("\{submission_\w+\}") subreddit_pattern = re.compile(r"{submission_\w+}")
message_pattern = re.compile("\{message_\w+\}") message_pattern = re.compile(r"{message_\w+\}")
user_pattern = re.compile("\{comment_karma\}|\{link_karma\}") user_pattern = re.compile(r"{comment_karma}|{link_karma}")
reddit_session = None reddit_session = None

View File

@ -56,9 +56,10 @@ class WindowTitle(Module):
# don't show window title when the window already has means # don't show window title when the window already has means
# to display it # to display it
if (not self.always_show and if (not self.always_show
(w.border == "normal" or w.type == "workspace" or and (w.border == "normal"
(p.layout in ("stacked", "tabbed") and len(p.nodes) > 1))): or w.type == "workspace"
or (p.layout in ("stacked", "tabbed") and len(p.nodes) > 1))):
return self.empty_title return self.empty_title
else: else:
title = w.name title = w.name
@ -74,10 +75,10 @@ class WindowTitle(Module):
# check if we need to update title due to changes # check if we need to update title due to changes
# in the workspace layout # in the workspace layout
layout_changed = ( layout_changed = (
hasattr(e, "binding") and hasattr(e, "binding")
(e.binding.command.startswith("layout") or and (e.binding.command.startswith("layout")
e.binding.command.startswith("move container") or or e.binding.command.startswith("move container")
e.binding.command.startswith("border")) or e.binding.command.startswith("border"))
) )
if title_changed or layout_changed: if title_changed or layout_changed:

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[pycodestyle]
ignore = E501,W503,W504,E741,E305,E722

View File

@ -189,7 +189,7 @@ class KeyConstraintDictAdvancedTests(unittest.TestCase):
class FormatPTests(unittest.TestCase): class FormatPTests(unittest.TestCase):
def test_escaping(self): def test_escaping(self):
assert util.formatp("[razamba \[ mabe \]]") == "razamba [ mabe ]" assert util.formatp(r"[razamba \[ mabe \]]") == "razamba [ mabe ]"
def test_numerical(self): def test_numerical(self):
assert util.formatp("[{t} - [schmuh {x}]]", t=1, x=2) == "1 - schmuh 2" assert util.formatp("[{t} - [schmuh {x}]]", t=1, x=2) == "1 - schmuh 2"