2018-08-05 00:15:53 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2019-05-28 18:29:36 +02:00
|
|
|
import argparse
|
2018-08-05 00:15:53 +02:00
|
|
|
import subprocess
|
2018-12-17 19:58:33 +01:00
|
|
|
if False:
|
2018-12-17 19:52:08 +01:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-in-production-scripts
|
2019-05-28 18:29:36 +02:00
|
|
|
from typing import List, Tuple
|
2018-08-05 00:15:53 +02:00
|
|
|
|
|
|
|
from zulint.printer import print_err, colors
|
|
|
|
|
2019-05-28 18:29:36 +02:00
|
|
|
|
2018-08-05 00:15:53 +02:00
|
|
|
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
|
2019-05-28 18:29:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def run_pyflakes(files, options, suppress_patterns=[]):
|
|
|
|
# type: (List[str], argparse.Namespace, List[Tuple[str, str]]) -> bool
|
|
|
|
if len(files) == 0:
|
|
|
|
return False
|
|
|
|
failed = False
|
|
|
|
color = next(colors)
|
|
|
|
pyflakes = subprocess.Popen(['pyflakes'] + files,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
assert pyflakes.stdout is not None # Implied by use of subprocess.PIPE
|
|
|
|
|
|
|
|
def suppress_line(line: str) -> bool:
|
|
|
|
for file_pattern, line_pattern in suppress_patterns:
|
|
|
|
if file_pattern in line and line_pattern in line:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
for ln in pyflakes.stdout.readlines() + pyflakes.stderr.readlines():
|
|
|
|
if options.full or not suppress_line(ln):
|
|
|
|
print_err('pyflakes', color, ln)
|
|
|
|
failed = True
|
|
|
|
return failed
|