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 425331 b9e9d507a53cfb13c5183adba4cc4489f62e1cce
parent 425330 fc0d9d4bf1bf539107e72f5b9f99314e181c6989
child 425332 14e28f7332c75560af8680f8d8bf524828260e23
push id66035
push userahalberstadt@mozilla.com
push dateFri, 06 Jul 2018 12:40:34 +0000
treeherderautoland@b9e9d507a53c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarco
bugs1473308
milestone63.0a1
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
.flake8
tools/lint/python/flake8.py
tools/lint/test/files/flake8/ext/bad.configure
tools/lint/test/test_flake8.py
--- a/.flake8
+++ b/.flake8
@@ -1,12 +1,16 @@
 [flake8]
 # 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/extensions/mortar/ppapi/,
+    browser/moz.configure,
+    build/moz.configure/*.configure,
     build/pymake/,
+    js/*.configure,
+    memory/moz.configure,
+    mobile/android/*.configure,
     node_modules,
     security/nss/,
     testing/mochitest/pywebsocket,
     tools/lint/test/files,
-
--- 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,'
                     '"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',
     ]
 
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__':
     mozunit.main()