Commit Graph

11 Commits

Author SHA1 Message Date
Andrew Halberstadt
c731fa1f2c Bug 1436639 - [lint] Make sure flake8 is run with same python as |mach lint| was, r=jmaher
This fixes a bug which can happen when the default version of python differs from
the version of python used with mach.

For example, mach explicitly looks for python2.7. This means running |mach lint -l flake8|
should also run flake8 with version 2.7. But if the default is python3, and flake8 is also
installed there, the subprocess call that invokes flake8 will run under python3. This can
lead to errors like "undefined name 'basestring'" and other 2to3 gotchas.

This patch ensures that we run the flake8 binary (and the pip for installing flake8) from
the same interpreter as mach, no matter the system default.

MozReview-Commit-ID: HSuMzDsAvsW

--HG--
extra : rebase_source : faf4c8c0eb6f46d8b50c2d9be9aa6f6d47e4e0cb
2018-02-07 23:28:33 -05:00
Andrew Halberstadt
1805dcb2d3 Bug 1436792 - [py-compat] Fix issue opening the temporary manifest on Windows, r=jmaher
MozReview-Commit-ID: FmA1K8osuqe

--HG--
extra : rebase_source : ee557c78b1c959caa10a7862fbc732b4cf11792e
2018-02-08 14:26:27 -05:00
Andrew Halberstadt
4c232ca311 Bug 1436792 - [py-compat] Improve error messaging when python is missing, r=jmaher
This patch makes a few changes around error handling:

1) Prints the name of the linter that produced non-json output
2) Changes the 'python not found' error to a warning (as this is not fatal)
3) Makes sure said warning only gets printed once (by moving it to the setup function)

MozReview-Commit-ID: Dkq7CulTs91

--HG--
extra : rebase_source : 5d4bd32a62264a88520c09420f5acd90edcdc740
2018-02-08 14:26:15 -05:00
Noemi Erli
b6751c929f Backed out changeset c9d150401eea (bug 1436639) for potential local workflow issues r=ahal on a CLOSED TREE 2018-02-08 19:45:07 +02:00
Andrew Halberstadt
eced3471fc Bug 1436639 - [lint] Make sure flake8 is run with same python as |mach lint| was, r=jmaher
This fixes a bug which can happen when the default version of python differs from
the version of python used with mach.

For example, mach explicitly looks for python2.7. This means running |mach lint -l flake8|
should also run flake8 with version 2.7. But if the default is python3, and flake8 is also
installed there, the subprocess call that invokes flake8 will run under python3. This can
lead to errors like "undefined name 'basestring'" and other 2to3 gotchas.

This patch ensures that we run:
python2.7 -m flake8

which explicitly runs flake8 against the same interpreter as mach, no matter the default.

MozReview-Commit-ID: HSuMzDsAvsW

--HG--
extra : rebase_source : d39f97ed0f82f4d2c81f044ef1f7dad0953a3d8d
2018-02-07 23:28:33 -05:00
Andrew Halberstadt
eb84bf741c Bug 1429457 - [mozlint] Create formal 'setup' mechanism for bootstrapping lint dependencies, r=gbrown
This allows linters to define a 'setup' method which will automatically be
called by |mach lint| before running the linter. Users can also explicitly run
these methods (without doing any actual linting) by running |mach lint --setup|.

MozReview-Commit-ID: 74aY1pfsaX1

--HG--
extra : rebase_source : e6a7d769ba14c996c7a77316928063fa46358c5a
2018-01-25 13:40:02 -05:00
Andrew Halberstadt
4a7ebcb3bb Bug 1434430 - [flake8] Upgrade version of flake8 used by |mach lint| to 3.5.0 r=rwood
MozReview-Commit-ID: BBtM4TEl4Ve

--HG--
extra : rebase_source : 94d276746401426c9adcae5c962380679ffcb083
2018-01-30 16:43:10 -05:00
Andrew Halberstadt
974ae38a52 Bug 1434430 - [flake8] Drop support for the FLAKE8 environment variable r=rwood
The flake8 linter requires a specific version of flake8, so that running it
locally vs in CI vs in mozreview will all produce the same results.

Allowing consumers to specify a custom flake8 binary via the FLAKE8 environment
variable, subverts that goal and can result in unexplained errors showing up in
some configurations but not others.

MozReview-Commit-ID: 1s0nC8ZO6Qi

--HG--
extra : rebase_source : f3913e2bce7770edf8deba18890f063975ca0844
2018-01-31 14:05:52 -05:00
Andrew Halberstadt
a5c7e81ae6 Bug 1398765 - Fix directory exclusion bug in py-compat linters, r=gps
The excluded directories aren't being properly handled in the py2/py3 compat
linters. In order for FileFinder to apply the exclusions properly they need
to either be relative to or contained by the base.

This means that currently the following will work:
./mach lint -l py2 <topsrcdir>
./mach lint -l py2 testing/mochitest

But this is broken:
./mach lint -l py2 testing

This change fixes the compat linters so exclude paths will be made relative
to the FileFinder base before passing them in. Any exclude not contained by
the base is simply discarded as it won't be relevant to that FileFinder
instance anyway.

MozReview-Commit-ID: LJx97TvKlSa

--HG--
extra : rebase_source : b8f0cb20ec5a88a33c26ace699ed9216b070f443
2017-09-11 09:03:53 -04:00
Andrew Halberstadt
3411e8b3d4 Bug 1391019 - Add py2 and py3 compatability linters, r=gps
check_compat.py was adapted from gps' check-py3-compat.py in mercurial:
https://www.mercurial-scm.org/repo/hg/file/tip/contrib/check-py3-compat.py

The py3 linter simply runs ast.parse(f) for each file being linted. Any syntax errors
are formatted as mozlint results and dumped to stdout as json. I looked into also
importing the file (using 3.5+'s importlib.util.spec_from_file_location), but there
were too many problems:

1. Lots of false positives (e.g module not found)
2. Some files seemed to run indefinitely on import

I decided to punt on importing for now, we can always investigate in a follow-up.

The py2 linter runs ast.parse(f), and also checks that the file has:
from __future__ import absolute_import, print_function

Initially every python file in the tree is excluded from the py2 check, though
at least this makes it easy to find+fix, and new files in un-excluded
directories will automatically be linted.

MozReview-Commit-ID: ABtq9dnPo9T

--HG--
extra : rebase_source : 60762937284d498514cd020b90cbfd2ba23f0b70
2017-08-31 10:12:02 -04:00
Andrew Halberstadt
3c2a0965ed Bug 1391019 - Move tools/lint/flake_/__init__.py to tools/lint/python/flake8.py, r=gps
This will allow us keep python related linting files in the same place.

MozReview-Commit-ID: ABtq9dnPo9T

--HG--
rename : tools/lint/flake8_/__init__.py => tools/lint/python/__init__.py
rename : tools/lint/flake8_/__init__.py => tools/lint/python/flake8.py
rename : tools/lint/flake8_/flake8_requirements.txt => tools/lint/python/flake8_requirements.txt
extra : rebase_source : 2568bc0bf8f4adbf8e0be73a54d5da068a8d81b0
2017-08-31 10:06:08 -04:00