2017-06-05 16:43:16 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
2018-08-04 23:56:46 +02:00
|
|
|
from zulint.printer import print_err, colors
|
2017-07-06 06:52:03 +02:00
|
|
|
|
2017-06-05 16:43:16 +02:00
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
2018-01-23 22:53:45 +01:00
|
|
|
suppress_patterns = [
|
|
|
|
(b'', b'imported but unused'),
|
|
|
|
(b'', b'redefinition of unused'),
|
|
|
|
|
|
|
|
# Our ipython startup pythonrc file intentionally imports *
|
|
|
|
(b"scripts/lib/pythonrc.py",
|
|
|
|
b" import *' used; unable to detect undefined names"),
|
|
|
|
|
|
|
|
# Special dev_settings.py import
|
|
|
|
(b'', b"from .prod_settings_template import *"),
|
|
|
|
|
|
|
|
(b"settings.py", b"settings import *' used; unable to detect undefined names"),
|
|
|
|
(b"settings.py", b"may be undefined, or defined from star imports"),
|
2018-01-23 22:55:55 +01:00
|
|
|
|
|
|
|
# Sphinx adds `tags` specially to the environment when running conf.py.
|
|
|
|
(b"docs/conf.py", b"undefined name 'tags'"),
|
2018-01-23 22:53:45 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-06-05 16:43:16 +02:00
|
|
|
def check_pyflakes(options, by_lang):
|
|
|
|
# type: (Any, Dict[str, List[str]]) -> bool
|
|
|
|
if len(by_lang['py']) == 0:
|
|
|
|
return False
|
|
|
|
failed = False
|
2017-07-06 06:52:03 +02:00
|
|
|
color = next(colors)
|
2017-06-05 16:43:16 +02:00
|
|
|
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
|
2017-07-06 06:52:03 +02:00
|
|
|
stdout=subprocess.PIPE,
|
2017-08-29 19:40:05 +02:00
|
|
|
stderr=subprocess.PIPE)
|
2017-08-04 07:34:27 +02:00
|
|
|
assert pyflakes.stdout is not None # Implied by use of subprocess.PIPE
|
2017-08-29 19:40:05 +02:00
|
|
|
for ln in pyflakes.stdout.readlines() + pyflakes.stderr.readlines():
|
2018-01-23 22:53:45 +01:00
|
|
|
if options.full or not suppress_line(ln):
|
2017-07-06 06:52:03 +02:00
|
|
|
print_err('pyflakes', color, ln)
|
|
|
|
failed = True
|
2017-06-05 16:43:16 +02:00
|
|
|
return failed
|