Bug 1277851 - [mozlint] Run flake8 directories that contain a .flake8 file separately, r=maja_zf

This is a crude workaround to get subdirectory .flake8 files working. Hopefully
this is temporary until flake8 3.0 is released with support for multiple config
files.

Note that .flake8 files that live outside of a directory that is explicitly
listed in the 'include' directive, will not be considered.

MozReview-Commit-ID: GtpUZHJKq52

--HG--
extra : rebase_source : 0294e135673a3b580316a46ec13e37749422edba
This commit is contained in:
Andrew Halberstadt 2016-06-03 10:39:32 -04:00
parent cdc5a62ddc
commit 7c3487a2d7
2 changed files with 33 additions and 13 deletions

View File

@ -35,10 +35,16 @@ overriden for a given subdirectory by creating a new ``.flake8`` file in the sub
that ``.flake8`` files cannot inherit from one another, so all configuration you wish to keep must
be re-defined.
.. warning::
Only ``.flake8`` files that live in a directory that is explicitly included in the ``include``
directive will be considered. See `bug 1277851`_ for more details.
For an overview of the supported configuration, see `flake8's documentation`_.
.. _Flake8: https://flake8.readthedocs.io/en/latest/
.. _pep8: http://pep8.readthedocs.io/en/latest/
.. _pyflakes: https://github.com/pyflakes/pyflakes
.. _mccabe: https://github.com/pycqa/mccabe
.. _bug 1277851: https://bugzilla.mozilla.org/show_bug.cgi?id=1277851
.. _flake8's documentation: https://flake8.readthedocs.io/en/latest/config.html

View File

@ -64,6 +64,21 @@ def process_line(line):
results.append(result.from_linter(LINTER, **res))
def run_process(cmdargs):
# flake8 seems to handle SIGINT poorly. Handle it here instead
# so we can kill the process without a cryptic traceback.
orig = signal.signal(signal.SIGINT, signal.SIG_IGN)
proc = ProcessHandler(cmdargs, env=os.environ,
processOutputLine=process_line)
proc.run()
signal.signal(signal.SIGINT, orig)
try:
proc.wait()
except KeyboardInterrupt:
proc.kill()
def lint(files, **lintargs):
binary = os.environ.get('FLAKE8')
if not binary:
@ -86,20 +101,19 @@ def lint(files, **lintargs):
if exclude:
cmdargs += ['--exclude', ','.join(lintargs['exclude'])]
cmdargs += files
# Run any paths with a .flake8 file in the directory separately so
# it gets picked up. This means only .flake8 files that live in
# directories that are explicitly included will be considered.
# See bug 1277851
no_config = []
for f in files:
if not os.path.isfile(os.path.join(f, '.flake8')):
no_config.append(f)
continue
run_process(cmdargs+[f])
# flake8 seems to handle SIGINT poorly. Handle it here instead
# so we can kill the process without a cryptic traceback.
orig = signal.signal(signal.SIGINT, signal.SIG_IGN)
proc = ProcessHandler(cmdargs, env=os.environ,
processOutputLine=process_line)
proc.run()
signal.signal(signal.SIGINT, orig)
try:
proc.wait()
except KeyboardInterrupt:
proc.kill()
if no_config:
run_process(cmdargs+no_config)
return results