mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
We were getting pyflakes lint error output without line numbers like this: pyflakes | if user_profile.is_realm_admin and pyflakes | ^ pyflakes | Apparently the cause was that stdout and stderr was getting mixed badly, creating "unused import"s lines that had the first of that error (containing the line number) just above. As a result, printing out the lines of output from pyflakes' merged stdout/stderr feed looked like this: b"zproject/settings.py:95: 'from .prod_settings import *' used; unable to detect undefined nameszerver/views/users.py:49:39: invalid syntax\n" Note the lack of newline in between the end of the first error at "names" and the start of the second at "zerver". This appears to be a change in Pyflakes behavior when we switched to Python 3; probably they're missing a flush() somewhere.
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
from __future__ import print_function
|
|
from __future__ import absolute_import
|
|
|
|
import subprocess
|
|
|
|
from .printer import print_err, colors
|
|
|
|
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
|
|
color = next(colors)
|
|
pyflakes = subprocess.Popen(['pyflakes'] + by_lang['py'],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE)
|
|
|
|
assert pyflakes.stdout is not None # Implied by use of subprocess.PIPE
|
|
for ln in pyflakes.stdout.readlines() + pyflakes.stderr.readlines():
|
|
if options.full or not (
|
|
b'imported but unused' in ln or
|
|
b'redefinition of unused' in ln or
|
|
# Our ipython startup pythonrc file intentionally imports *
|
|
(b"scripts/lib/pythonrc.py" in ln and
|
|
b" import *' used; unable to detect undefined names" in ln) or
|
|
# Special dev_settings.py import
|
|
b"from .prod_settings_template import *" in ln or
|
|
(b"settings.py" in ln and
|
|
(b"settings import *' used; unable to detect undefined names" in ln or
|
|
b"may be undefined, or defined from star imports" in ln))):
|
|
|
|
print_err('pyflakes', color, ln)
|
|
failed = True
|
|
return failed
|