diff --git a/tools/linter_lib/pep8.py b/tools/linter_lib/pep8.py index ad729dbeae..b2ff0a6efb 100644 --- a/tools/linter_lib/pep8.py +++ b/tools/linter_lib/pep8.py @@ -3,27 +3,12 @@ from __future__ import absolute_import import subprocess -from zulint.printer import print_err, colors +from zulint.linters import run_pycodestyle from typing import List def check_pep8(files): # type: (List[str]) -> bool - - def run_pycodestyle(files, ignored_rules): - # type: (List[str], List[str]) -> bool - failed = False - color = next(colors) - pep8 = subprocess.Popen( - ['pycodestyle'] + files + ['--ignore={rules}'.format(rules=','.join(ignored_rules))], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - assert pep8.stdout is not None # Implied by use of subprocess.PIPE - for line in iter(pep8.stdout.readline, b''): - print_err('pep8', color, line) - failed = True - return failed - - failed = False ignored_rules = [ # Each of these rules are ignored for the explained reason. @@ -96,9 +81,4 @@ def check_pep8(files): # 'W504', ] - if len(files) == 0: - return False - - failed = run_pycodestyle(files, ignored_rules) - - return failed + return run_pycodestyle(files, ignored_rules) diff --git a/tools/zulint/linters.py b/tools/zulint/linters.py new file mode 100644 index 0000000000..a0e6ec3563 --- /dev/null +++ b/tools/zulint/linters.py @@ -0,0 +1,23 @@ +from __future__ import print_function +from __future__ import absolute_import + +import subprocess +from typing import List + +from zulint.printer import print_err, colors + +def run_pycodestyle(files, ignored_rules): + # type: (List[str], List[str]) -> bool + if len(files) == 0: + return False + + failed = False + color = next(colors) + pep8 = subprocess.Popen( + ['pycodestyle'] + files + ['--ignore={rules}'.format(rules=','.join(ignored_rules))], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + assert pep8.stdout is not None # Implied by use of subprocess.PIPE + for line in iter(pep8.stdout.readline, b''): + print_err('pep8', color, line) + failed = True + return failed