-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pylint (via pantsbuild) #5837
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Eric-Arellano
approved these changes
Dec 6, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting!
64782f7
to
db085ad
Compare
amanda11
approved these changes
Dec 9, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Also include note about why st2*/bin/BUILD has skip_pylint=True
When pylint_plugins/ is on PYTHONPATH, we cannot use a relative import. We do not add it to PYTHONPATH in the Makefile, so we need the relative import. So, use a try/catch block to support both methods until we can drop the Makefile.
db085ad
to
03ebd0a
Compare
rush-skills
approved these changes
Dec 11, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
external dependency
infrastructure: ci/cd
maintenance
pantsbuild
size/XL
PR that changes 500-999 lines. Consider splitting work into several ones that easier to review.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This is another part of introducing pants, as discussed in various TSC meetings.
Related PRs can be found in:
Overview of this PR
This configures pants to use
pylint
when running thelint
goal. Configuring pylint is multi-faceted. We have to add config inpants.toml
(like the pylint version to use and adding a newpylint_plugins
resolve), generating lockfiles for pylint and pylint_plugins, and addingskip_pylint=True
to a lot ofBUILD
files.I recommend reviewing this PR by stepping through the commits.
This adds a new resolve,
pylint_plugins
, for the code underpylint_plugins/
. This is separate from our defaultst2
resolve. I would just re-use thepylint
resolve and lockfile (for thepylint
tool), but pants does not support reusing a tool's config like that yet (There is discussion in the pants community on how to make this work better. We'll see how that goes.). So, we have to duplicate the version requirements in two places, and have two lockfiles that have practically the same contents.Relevant Pants documentation
./pants lint
goal./pants generate-lockfiles
goal68f1921 record pylint version requirements
First, this commit records the pylint version in
pants.toml
. This version is for thepylint
resolve, which is used whenever pants is runningpylint
. It also adds thesetuptools
dep, becausepylint
fails to report that it usespkg_resources
from setuptools, and setuptools is NOT installed by default with pants+PEX.st2/pants.toml
Lines 147 to 151 in 68f1921
Second, this commit records the pylint version in
pylint_plugins/BUILD
. This version is for thepylint_plugins
resolve, which is used whenever pants is running linters/tests/etc on the code inpylint_plugins/
. This mirrorspants.toml
by also including the same setuptools requirement.st2/pylint_plugins/BUILD
Lines 7 to 15 in 68f1921
Third, this commit adds an
astroid
dependency inpylint_plugins/BUILD
, because that is actually the only third party dependency of ourpylint_plugins/
code. But, we do not define a version for astroid; instead, the version ofastroid
gets constrained because we also requirepylint
, specifying the same as inpants.toml
.pylint
has narrow support for which versions of astroid it can use, so trying to maintain a version of both pylint and astroid proved irritating. Instead, we rely on the lockfile to keep things consistent in-between upgrading pylint.st2/pylint_plugins/BUILD
Lines 17 to 21 in 68f1921
395c869 add new resolve for pylint_plugins/ deps
First, this commit defines the
pylint_plugins
resolve by setting the path to the lockfile (which will be generated in a later commit).st2/pants.toml
Lines 97 to 99 in 395c869
Second, this commit changes the
__defaults__
for thepylint_plugins/
dir so that everything in that dir uses the new resolve:st2/pylint_plugins/BUILD
Lines 1 to 5 in 395c869
Third, this commit drops an implicit dependency on the root
conftest.py
file. Code in thepylint_plugins
resolve cannot import code in thest2
resolve. pants will error if something tries to do that. (Plus, this renames the target name fromtest_utils0
totest_utils
for clarity (the original name was generated by./pants tailor
).st2/pylint_plugins/BUILD
Lines 9 to 14 in 395c869
9ac8365 enable pylint via pants
This registers the pylint backend in
pants.toml
, and tells pants where our.pylintrc
file is, and where our pylint plugins are.Effectively this covers how the Makefile runs
pylint
with args:--rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models --load-plugins=pylint_plugins.db_models
st2/Makefile
Line 346 in 9ac8365
e085f52 Generate pylint* lockfiles
This generates both lockfiles:
lockfiles/pylint.lock
andlockfiles/pylint_plugins.lock
. These files are exactly the same, except for the name of the resolve (pylint
vspylint_plugins
). Each lockfile is 385 lines long. So, 770 of the lines in this PR are auto-generated.add
skip_pylint=True
metadata to BUILD filesThe next three commits add
skip_pylint=True
in a variety of contexts where running pylint doesn't work well. This runs pylint on a lot more of our code than the Makefile does, but skips files as needed. Maybe in the future we can enable more of our code.In particular this skips running pylint on:
st2*/bin
dirs (because the script names in bin ended up shadowing the modules they were importing and the-
in other script names was problematic. see: Add way to disable module caching for specific files pylint-dev/pylint#2095)There are two ways we add this metadata. We either add
skip_pylint=True
to individual targets, or we can skip entire directories with__defaults__
:st2/st2actions/tests/BUILD
Lines 1 to 5 in 4fd2f06
f4cb99f fix pants dep inference for pylint_plugins
It turns out, we have to use different pylint args when pants runs
pylint
vs when the legacyMakefile
runs it.pants
adds source_roots to PYTHONPATH, sopylint_plugins/
is on the PYTHONPATH which makesapi_plugins
andapi_models
top-level modules. When it is not on the PYTHONPATH, as in the Makefile,pylint_plugins
is the top-level module. So, we had to just an import in the python test, and the args in `pants.toml.4c7888d use pylint -E under pants
The Makefile uses
-E
when running pylint:st2/Makefile
Line 346 in 4c7888d
I had to look up what that meant. Running pylint without that generates a lot of warnings. It turns out
-E
is short for--errors-only
. So, I used--errors-only
instead of-E
to remind myself of what it does in the future. Hopefully we can drop this at some point.st2/pants.toml
Lines 161 to 162 in 4c7888d