Extract tools/linter_lib/pyflakes.py

This commit is contained in:
Steve Howell 2017-06-05 08:43:16 -06:00 committed by Tim Abbott
parent 29affda956
commit 9fab41aebb
2 changed files with 42 additions and 35 deletions

View File

@ -13,7 +13,7 @@ from lib import sanity_check
sanity_check.check_venv(__file__)
import lister
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple
from typing import cast, Callable, Dict, Iterator, List
@contextmanager
def bright_red_output():
@ -28,40 +28,6 @@ def bright_red_output():
sys.stdout.write('\x1B[0m')
def check_pyflakes(options, by_lang):
# type: (Any, Dict[str, List[str]]) -> bool
if len(by_lang['py']) == 0:
return False
failed = False
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True)
# pyflakes writes some output (like syntax errors) to stderr. :/
for pipe in (pyflakes.stdout, pyflakes.stderr):
assert(pipe is not None) # onvince mypy that pipe cannot be None
for ln in pipe:
if options.full or not (
('imported but unused' in ln or
'redefinition of unused' in ln or
# Our ipython startup pythonrc file intentionally imports *
("scripts/lib/pythonrc.py" in ln and
" import *' used; unable to detect undefined names" in ln) or
# Special dev_settings.py import
"from .prod_settings_template import *" in ln or
("settings.py" in ln and
("settings import *' used; unable to detect undefined names" in ln or
"may be undefined, or defined from star imports" in ln)) or
("zerver/tornado/ioloop_logging.py" in ln and
"redefinition of function 'instrument_tornado_ioloop'" in ln) or
("zephyr_mirror_backend.py:" in ln and
"redefinition of unused 'simplejson' from line" in ln))):
sys.stdout.write(ln)
failed = True
return failed
def check_pep8(files):
# type: (List[str]) -> bool
@ -220,6 +186,7 @@ def run():
from tools.linter_lib.custom_check import build_custom_checkers
from tools.linter_lib.exclude import EXCLUDED_FILES
from tools.linter_lib.pyflakes import check_pyflakes
from tools.lib.test_script import (
get_provisioning_status,

View File

@ -0,0 +1,40 @@
from __future__ import print_function
from __future__ import absolute_import
import subprocess
import sys
from typing import Any, Dict, List
def check_pyflakes(options, by_lang):
# type: (Any, Dict[str, List[str]]) -> bool
if len(by_lang['py']) == 0:
return False
failed = False
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True)
# pyflakes writes some output (like syntax errors) to stderr. :/
for pipe in (pyflakes.stdout, pyflakes.stderr):
assert(pipe is not None) # convince mypy that pipe cannot be None
for ln in pipe:
if options.full or not (
('imported but unused' in ln or
'redefinition of unused' in ln or
# Our ipython startup pythonrc file intentionally imports *
("scripts/lib/pythonrc.py" in ln and
" import *' used; unable to detect undefined names" in ln) or
# Special dev_settings.py import
"from .prod_settings_template import *" in ln or
("settings.py" in ln and
("settings import *' used; unable to detect undefined names" in ln or
"may be undefined, or defined from star imports" in ln)) or
("zerver/tornado/ioloop_logging.py" in ln and
"redefinition of function 'instrument_tornado_ioloop'" in ln) or
("zephyr_mirror_backend.py:" in ln and
"redefinition of unused 'simplejson' from line" in ln))):
sys.stdout.write(ln)
failed = True
return failed