From 01ca80736773cf46f320ccf59a5d5c40cebec5fa Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Thu, 7 Feb 2019 20:17:02 +0000 Subject: [PATCH] Bug 1515746 - [flake8] Unsupport subdir .flake8 files and use new 'per-file-ignores' config instead, r=egao This removes all .flake8 files except for the one at the root of the repo. Instead we use the new 'per-file-ignores' config introduced in 3.7. To ignore specific errors in a subdirectory, add a line like this to the root .flake8: [per-file-ignores] path/to/subdir/*: E100, F200, ... The reasons for this change are: 1. Unblock flake8 blacklist (bug 1367092). 2. Simplify configuration and code. 3. Encourage more consistent styling. 4. Improve performance. 5. Greater editor consistency. Differential Revision: https://phabricator.services.mozilla.com/D18354 --HG-- extra : moz-landing-system : lando --- .flake8 | 9 +++++ build/moz.configure/.flake8 | 5 --- ipc/ipdl/.flake8 | 5 --- security/manager/.flake8 | 14 ------- testing/firefox-ui/.flake8 | 3 -- testing/marionette/client/.flake8 | 5 --- testing/marionette/harness/.flake8 | 7 ---- testing/marionette/puppeteer/.flake8 | 3 -- testing/mozharness/configs/.flake8 | 33 ---------------- tools/lint/python/flake8.py | 57 +++++++++------------------- tools/lint/test/test_flake8.py | 7 +--- 11 files changed, 29 insertions(+), 119 deletions(-) delete mode 100644 build/moz.configure/.flake8 delete mode 100644 ipc/ipdl/.flake8 delete mode 100644 security/manager/.flake8 delete mode 100644 testing/firefox-ui/.flake8 delete mode 100644 testing/marionette/client/.flake8 delete mode 100644 testing/marionette/harness/.flake8 delete mode 100644 testing/marionette/puppeteer/.flake8 delete mode 100644 testing/mozharness/configs/.flake8 diff --git a/.flake8 b/.flake8 index fdff3eefa692..a8b95735fa00 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,12 @@ exclude = mobile/android/*.configure, node_modules, security/nss/, + testing/firefox-ui/**/__init__.py, + testing/marionette/**/__init__.py, + testing/marionette/harness/marionette_harness/runner/mixins, + testing/marionette/harness/marionette_harness/tests, testing/mochitest/pywebsocket, + testing/mozharness/configs/test/test_malformed.py, tools/lint/test/files, tools/infer/test/*.configure, tools/crashreporter/*.configure, @@ -33,3 +38,7 @@ ignore = # F723: syntax error in type comment # text contains quotes which breaks our custom JSON formatter F723, E121, E123, E126, E129, E133, E226, E241, E242, E402, E704, E741, W503, + +per-file-ignores = + ipc/ipdl/*: F403, F405 + testing/mozharness/configs/*: E124, E127, E128, E131, E231, E261, E265, E266, E501, W391 diff --git a/build/moz.configure/.flake8 b/build/moz.configure/.flake8 deleted file mode 100644 index ba2490f17789..000000000000 --- a/build/moz.configure/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -# F821: undefined name -# This is the moz.configure style -ignore = F821 - diff --git a/ipc/ipdl/.flake8 b/ipc/ipdl/.flake8 deleted file mode 100644 index 46f8ed423e2a..000000000000 --- a/ipc/ipdl/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -# See http://pep8.readthedocs.io/en/latest/intro.html#configuration -ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E741, F405, F403, W504 -max-line-length = 99 - diff --git a/security/manager/.flake8 b/security/manager/.flake8 deleted file mode 100644 index ed34b8860635..000000000000 --- a/security/manager/.flake8 +++ /dev/null @@ -1,14 +0,0 @@ -[flake8] -# E128: continuation line under-indented for visual indent. -# Best visual indent typically determined based on context. -# E261: at least two spaces before inline comment. -# Not PSM style. -# E302: expected 2 blank lines, found 1. -# Not really PSM style. -ignore = E128,E261,E302,W605,W504 - -# PSM style is to stick close to 80 chars, but 4 space indentation means we -# sometimes need more space. -max-line-length = 100 - -filename = *.py diff --git a/testing/firefox-ui/.flake8 b/testing/firefox-ui/.flake8 deleted file mode 100644 index b242ff9e3673..000000000000 --- a/testing/firefox-ui/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -exclude = - __init__.py, diff --git a/testing/marionette/client/.flake8 b/testing/marionette/client/.flake8 deleted file mode 100644 index d30709f8d6a2..000000000000 --- a/testing/marionette/client/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -exclude = - __init__.py, - disti/*, - build/*, diff --git a/testing/marionette/harness/.flake8 b/testing/marionette/harness/.flake8 deleted file mode 100644 index ff690d9f09a9..000000000000 --- a/testing/marionette/harness/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -exclude = - __init__.py, - disti/*, - build/*, - marionette_harness/runner/mixins/*, - marionette_harness/tests/*, diff --git a/testing/marionette/puppeteer/.flake8 b/testing/marionette/puppeteer/.flake8 deleted file mode 100644 index b242ff9e3673..000000000000 --- a/testing/marionette/puppeteer/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -exclude = - __init__.py, diff --git a/testing/mozharness/configs/.flake8 b/testing/mozharness/configs/.flake8 deleted file mode 100644 index 4e62b3e6cf59..000000000000 --- a/testing/mozharness/configs/.flake8 +++ /dev/null @@ -1,33 +0,0 @@ -[flake8] -ignore = - # From root - E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, W605, W504, - # The following errors should be fixed eventually - # line too long - E501, - # at least two spaces before inline comment - E261, - # continuation line under-indented for visual indent - E128, - # whitespace before ':' - E203, - # blank line at end of file - W391, - # multiple statements on one line - E702, - # closing bracket does not match visual indentation - E124, - # missing whitespace after ':' - E231, - # continuation line over-indented for visual indent - E127, - # too many leading '#' for block comment - E266, - # comment should start with '# ' - E262, E265, - # continuation line unaligned for hanging indent - E131, - # continuation line missing indentation or outdented - E122, -exclude = - test/test_malformed.py diff --git a/tools/lint/python/flake8.py b/tools/lint/python/flake8.py index ffafd763be29..392cb880a8ed 100644 --- a/tools/lint/python/flake8.py +++ b/tools/lint/python/flake8.py @@ -8,13 +8,11 @@ import platform import signal import subprocess import sys -from collections import defaultdict from mozprocess import ProcessHandlerMixin from mozlint import result from mozlint.util import pip -from mozlint.pathutils import get_ancestors_by_name here = os.path.abspath(os.path.dirname(__file__)) @@ -95,16 +93,6 @@ class Flake8Process(ProcessHandlerMixin): signal.signal(signal.SIGINT, orig) -def run_process(config, cmd): - proc = Flake8Process(config, cmd) - proc.run() - try: - proc.wait() - except KeyboardInterrupt: - proc.kill() - return 1 - - def setup(root): if not pip.reinstall_program(FLAKE8_REQUIREMENTS_PATH): print(FLAKE8_INSTALL_ERROR) @@ -116,42 +104,33 @@ def lint(paths, config, **lintargs): global results results = [] + config_path = os.path.join(lintargs['root'], '.flake8') cmdargs = [ os.path.join(bindir, 'flake8'), + '--config', config_path, '--format', '{"path":"%(path)s","lineno":%(row)s,' '"column":%(col)s,"rule":"%(code)s","message":"%(text)s"}', '--filename', ','.join(['*.{}'.format(e) for e in config['extensions']]), ] - fix_cmdargs = [ - os.path.join(bindir, 'autopep8'), - '--global-config', os.path.join(lintargs['root'], '.flake8'), - '--in-place', '--recursive', - ] + if lintargs.get('fix'): + fix_cmdargs = [ + os.path.join(bindir, 'autopep8'), + '--global-config', config_path, + '--in-place', '--recursive', + ] - if config.get('exclude'): - fix_cmdargs.extend(['--exclude', ','.join(config['exclude'])]) + if config.get('exclude'): + fix_cmdargs.extend(['--exclude', ','.join(config['exclude'])]) - # 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 - paths_by_config = defaultdict(list) - for path in paths: - configs = get_ancestors_by_name('.flake8', path, lintargs['root']) - paths_by_config[os.pathsep.join(configs) if configs else 'default'].append(path) + subprocess.call(fix_cmdargs + paths) - for configs, paths in paths_by_config.items(): - if lintargs.get('fix'): - subprocess.call(fix_cmdargs + paths) - - cmd = cmdargs[:] - if configs != 'default': - configs = reversed(configs.split(os.pathsep)) - cmd.extend(['--append-config={}'.format(c) for c in configs]) - - cmd.extend(paths) - if run_process(config, cmd): - break + proc = Flake8Process(config, cmdargs + paths) + proc.run() + try: + proc.wait() + except KeyboardInterrupt: + proc.kill() + return 1 return results diff --git a/tools/lint/test/test_flake8.py b/tools/lint/test/test_flake8.py index dc3b9ba4fa7f..41740ea80e34 100644 --- a/tools/lint/test/test_flake8.py +++ b/tools/lint/test/test_flake8.py @@ -18,14 +18,11 @@ def test_lint_single_file(lint, paths): assert len(results) == 2 -def test_lint_custom_config(lint, paths): +def test_lint_custom_config_ignored(lint, paths): results = lint(paths('custom')) - assert len(results) == 0 + assert len(results) == 2 results = lint(paths('custom/good.py')) - assert len(results) == 0 - - results = lint(paths('custom', 'bad.py')) assert len(results) == 2