From 0d7156b5b10efc88a32d7bf87ea3d10cbd1e207a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B3=D0=BE=D1=80?= Date: Mon, 6 Aug 2018 16:29:19 +0300 Subject: [PATCH] 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 --- ci-build.sh | 2 +- i3pystatus/core/imputil.py | 6 +++--- i3pystatus/core/util.py | 2 +- i3pystatus/mpd.py | 4 ++-- i3pystatus/network.py | 4 ++-- i3pystatus/now_playing.py | 8 ++++---- i3pystatus/pulseaudio/__init__.py | 2 +- i3pystatus/reddit.py | 6 +++--- i3pystatus/window_title.py | 15 ++++++++------- setup.cfg | 2 ++ tests/test_core_util.py | 2 +- 11 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 setup.cfg diff --git a/ci-build.sh b/ci-build.sh index 58493f2..e9d233c 100755 --- a/ci-build.sh +++ b/ci-build.sh @@ -9,7 +9,7 @@ BUILD=${1:-ci-build} rm -rf ${BUILD}/ mkdir -p $BUILD -python3 -mpycodestyle --ignore E501,E741,E305,E722 i3pystatus tests +python3 -mpycodestyle i3pystatus tests # Check that the setup.py script works rm -rf ${BUILD}/test-install ${BUILD}/test-install-bin diff --git a/i3pystatus/core/imputil.py b/i3pystatus/core/imputil.py index 453e647..2e6f0cb 100644 --- a/i3pystatus/core/imputil.py +++ b/i3pystatus/core/imputil.py @@ -13,9 +13,9 @@ class ClassFinder: def predicate_factory(self, module): def predicate(obj): return ( - inspect.isclass(obj) and - issubclass(obj, self.baseclass) and - obj.__module__ == module.__name__ + inspect.isclass(obj) + and issubclass(obj, self.baseclass) + and obj.__module__ == module.__name__ ) return predicate diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index 54abe49..8e7c698 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -271,7 +271,7 @@ def formatp(string, **kwargs): return subtree def merge_tree(items): - return "".join(flatten(items)).replace("\]", "]").replace("\[", "[") + return "".join(flatten(items)).replace(r"\]", "]").replace(r"\[", "[") stack = build_stack(string) tree = build_tree(stack, 0) diff --git a/i3pystatus/mpd.py b/i3pystatus/mpd.py index df0432c..bab9e2f 100644 --- a/i3pystatus/mpd.py +++ b/i3pystatus/mpd.py @@ -171,8 +171,8 @@ cleartext to the server.)"), full_text = formatp(self.format, **fdict).strip() full_text_len = len(full_text) if full_text_len > self.max_len and self.max_len > 0: - shrink = floor((self.max_len - full_text_len) / - len(self.truncate_fields)) - 1 + shrink = floor((self.max_len - full_text_len) + / len(self.truncate_fields)) - 1 for key in self.truncate_fields: fdict[key] = fdict[key][:shrink] + "…" diff --git a/i3pystatus/network.py b/i3pystatus/network.py index 55f32e1..fd52366 100644 --- a/i3pystatus/network.py +++ b/i3pystatus/network.py @@ -353,8 +353,8 @@ class Network(IntervalModule, ColorRangeModule): def init(self): # 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 - any(s in f for f in self.format_active_up.values()) + if any(s in self.format_down or s in self.format_up + or any(s in f for f in self.format_active_up.values()) for s in ['essid', 'freq', 'quality', 'quality_bar']): get_wifi_info = True else: diff --git a/i3pystatus/now_playing.py b/i3pystatus/now_playing.py index 2ae9106..4d35f4c 100644 --- a/i3pystatus/now_playing.py +++ b/i3pystatus/now_playing.py @@ -160,10 +160,10 @@ https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html "title": currentsong.get("xesam:title", ""), "album": currentsong.get("xesam:album", ""), "artist": ", ".join(currentsong.get("xesam:artist", "")), - "song_length": TimeWrapper((currentsong.get("mpris:length") or - 0) / 1000 ** 2), - "song_elapsed": TimeWrapper((get_prop("Position") or 0) / - 1000 ** 2), + "song_length": TimeWrapper( + (currentsong.get("mpris:length") or 0) / 1000 ** 2), + "song_elapsed": TimeWrapper( + (get_prop("Position") or 0) / 1000 ** 2), "filename": "", } diff --git a/i3pystatus/pulseaudio/__init__.py b/i3pystatus/pulseaudio/__init__.py index 4c5cff9..0c070b8 100644 --- a/i3pystatus/pulseaudio/__init__.py +++ b/i3pystatus/pulseaudio/__init__.py @@ -210,7 +210,7 @@ class PulseAudio(Module, ColorRangeModule): if self.move_sink_inputs: sink_inputs = subprocess.check_output("pacmd list-sink-inputs".split(), 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) # Not all applications can be moved and pulseaudio, and when diff --git a/i3pystatus/reddit.py b/i3pystatus/reddit.py index ba5ce5c..6adc954 100644 --- a/i3pystatus/reddit.py +++ b/i3pystatus/reddit.py @@ -75,9 +75,9 @@ class Reddit(IntervalModule): _permalink = "" _url = "" - subreddit_pattern = re.compile("\{submission_\w+\}") - message_pattern = re.compile("\{message_\w+\}") - user_pattern = re.compile("\{comment_karma\}|\{link_karma\}") + subreddit_pattern = re.compile(r"{submission_\w+}") + message_pattern = re.compile(r"{message_\w+\}") + user_pattern = re.compile(r"{comment_karma}|{link_karma}") reddit_session = None diff --git a/i3pystatus/window_title.py b/i3pystatus/window_title.py index 359e1d2..9460132 100644 --- a/i3pystatus/window_title.py +++ b/i3pystatus/window_title.py @@ -56,9 +56,10 @@ class WindowTitle(Module): # don't show window title when the window already has means # to display it - if (not self.always_show and - (w.border == "normal" or w.type == "workspace" or - (p.layout in ("stacked", "tabbed") and len(p.nodes) > 1))): + if (not self.always_show + and (w.border == "normal" + or w.type == "workspace" + or (p.layout in ("stacked", "tabbed") and len(p.nodes) > 1))): return self.empty_title else: title = w.name @@ -74,10 +75,10 @@ class WindowTitle(Module): # check if we need to update title due to changes # in the workspace layout layout_changed = ( - hasattr(e, "binding") and - (e.binding.command.startswith("layout") or - e.binding.command.startswith("move container") or - e.binding.command.startswith("border")) + hasattr(e, "binding") + and (e.binding.command.startswith("layout") + or e.binding.command.startswith("move container") + or e.binding.command.startswith("border")) ) if title_changed or layout_changed: diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..9a86d68 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[pycodestyle] +ignore = E501,W503,W504,E741,E305,E722 diff --git a/tests/test_core_util.py b/tests/test_core_util.py index 5b9680e..c1c13f6 100644 --- a/tests/test_core_util.py +++ b/tests/test_core_util.py @@ -189,7 +189,7 @@ class KeyConstraintDictAdvancedTests(unittest.TestCase): class FormatPTests(unittest.TestCase): def test_escaping(self): - assert util.formatp("[razamba \[ mabe \]]") == "razamba [ mabe ]" + assert util.formatp(r"[razamba \[ mabe \]]") == "razamba [ mabe ]" def test_numerical(self): assert util.formatp("[{t} - [schmuh {x}]]", t=1, x=2) == "1 - schmuh 2"