Bug 1473308 - [flake8] Pass custom extension list into the flake8 binary r=marco
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 06 Jul 2018 12:39:39 +0000
changeset 425314 b9e9d507a53cfb13c5183adba4cc4489f62e1cce
parent 425313 fc0d9d4bf1bf539107e72f5b9f99314e181c6989
child 425315 14e28f7332c75560af8680f8d8bf524828260e23
push id34243
push userbtara@mozilla.com
push dateFri, 06 Jul 2018 21:59:02 +0000
treeherdermozilla-central@79197e2d630a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1473308 - [flake8] Pass custom extension list into the flake8 binary r=marco We're supposed to be linting both .py and .configure files with flake8. However we never inform flake8 of this fact. So e.g running: ./mach lint -l flake8 mobile/android Will not lint mobile/android/gradle.configure. However since flake8 will run on a file regardless of its extension if you pass that file in directly, it means that running: ./mach lint -l flake8 mobile/android/gradle.configure *Will* cause the file to be linted (and subsequently fail). This fix makes sure that flake8 knows to look at .configure files in addition to .py. Since this means many .configure files around the tree will start getting linted for the first time, we need to exclude them until they can be fixed. Differential Revision: https://phabricator.services.mozilla.com/D1975
--- a/.flake8
+++ b/.flake8
@@ -1,12 +1,16 @@
 # See http://pep8.readthedocs.io/en/latest/intro.html#configuration
 ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E741
 max-line-length = 99
 exclude =
+    browser/moz.configure,
+    build/moz.configure/*.configure,
+    js/*.configure,
+    memory/moz.configure,
+    mobile/android/*.configure,
--- a/tools/lint/python/flake8.py
+++ b/tools/lint/python/flake8.py
@@ -119,16 +119,17 @@ def lint(paths, config, **lintargs):
     # TODO don't store results in a global
     global results
     results = []
     cmdargs = [
         os.path.join(bindir, 'flake8'),
         '--format', '{"path":"%(path)s","lineno":%(row)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',
new file mode 100644
--- /dev/null
+++ b/tools/lint/test/files/flake8/ext/bad.configure
@@ -0,0 +1,2 @@
+# unused import
+import os
--- a/tools/lint/test/test_flake8.py
+++ b/tools/lint/test/test_flake8.py
@@ -75,10 +75,15 @@ def test_lint_custom_config_from_parent_
 @pytest.mark.xfail(reason="Bug 1277851 - 'exclude' argument is ignored")
 def test_lint_excluded_file(lint, paths):
     paths = paths('bad.py')
     results = lint(paths, exclude=paths)
     assert len(results) == 0
+def test_lint_uses_custom_extensions(lint, paths):
+    assert len(lint(paths('ext'))) == 1
+    assert len(lint(paths('ext/bad.configure'))) == 1
 if __name__ == '__main__':