Configure pants to look for plugins in pants-plugins/ directory#5842
Merged
cognifloyd merged 4 commits intomasterfrom Dec 9, 2022
Merged
Configure pants to look for plugins in pants-plugins/ directory#5842cognifloyd merged 4 commits intomasterfrom
cognifloyd merged 4 commits intomasterfrom
Conversation
Eric-Arellano
approved these changes
Dec 7, 2022
cognifloyd
commented
Dec 7, 2022
Comment on lines
+9
to
+11
| pants_requirements( | ||
| name="pants", | ||
| testutil=False, |
Member
Author
There was a problem hiding this comment.
I set testutil=False (defaults to True), because I haven't used it so far. We can add it once we introduce some test(s) that use it.
see: https://www.pantsbuild.org/docs/reference-pants_requirements#codetestutilcode
828a1a5 to
4bf55ad
Compare
nzlosh
approved these changes
Dec 8, 2022
This configures pants so we can start adding plugins in pants-plugins.
4bf55ad to
ac1b06b
Compare
amanda11
approved these changes
Dec 9, 2022
Contributor
amanda11
left a comment
There was a problem hiding this comment.
LGTM - and thanks for the comments like one on pants-plugins so we know how we have to put to the same version as pants interpreter.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 and generates a lockfile for a new
pants-plugins/directory.In follow-up PRs I will add several plugins for pants to improve Developer Experience and simplify config we need to add in a lot of directories. This PR adds the prerequisite global config we need before introducing any of those plugins.
This adjusts config in two files:
pants.tomlandpants-plugins/BUILD.Relevant Pants documentation
pants_requirementspants plugins
The pants plugin framework is very flexible. The core engine of pants is written in rust (for speed), but the plugin API is python. Each of the backends we have enabled, black, flake8, etc, are implemented as pants plugins. Plus, we can (and will) add in-repo plugins to handle some of the unique aspects of how StackStorm is organized.
By convention in-repo plugins go in the
pants-plugins/directory.pants-plugins have a dependency on pants itself
At risk of stating the obvious, all of our in-repo pants-plugins (once added, will) depend on pants. We could add a
python_requirementtarget to capture that dependency, but then updating pants would require updating the same version number in 2 places. Luckily pants provides some tools to help here.In
pants.toml, we register thepants.backend.plugin_developmentbackend to get access to thepants_requirementstarget.st2/pants.toml
Line 25 in 87af527
And then use
pants_requirementsinpants-plugins/BuILD:st2/pants-plugins/BUILD
Lines 8 to 12 in 87af527
Configure pants to find plugins in
pants-plugins/First we add
pants-pluginsto[GLOBAL].pythonpath. This pythonpath only refers to the path pants uses when loading itself, not our code or the other tools we use.st2/pants.toml
Line 10 in 87af527
And we register another source root, so we can run black, flake8 and friends on our
pants-plugins/code:st2/pants.toml
Lines 84 to 85 in 87af527
pants-pluginsresolve and lockfileWhen we add an in-repo plugins we should keep this warning from the docs in mind:
To better isolate the pants-plugins code from the rest of our code, we create a new resolve for it.
This registers the resolve+lockfile in
pants.toml:st2/pants.toml
Line 105 in 87af527
And then this adds python interpreter constraints to that resolve. These constraints are for code that runs in pants, so we match the python versions that pants itself uses.
st2/pants.toml
Lines 107 to 113 in 87af527
And we use
__defaults__to make sure all of the plugin code, including ourpants_requirementstarget, are part of thepants-pluginsresolve. aside: I also addedskip_pylint=Truelike in #5837. Because we're using__defaults__we do not have to merge #5837 before this PR. The setting will apply as soon as it is available.st2/pants-plugins/BUILD
Lines 1 to 6 in 87af527
And finally, generate
lockfiles/pants-plugins.lockusing./pants generate-lockfiles --resolve=pants-plugins.pants-plugins/README.mdI also added a skeleton readme to explain what goes in the
pants-plugins/directory.