Configure pants to look for plugins in pants-plugins/ directory #5842
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.toml
andpants-plugins/BUILD
.Relevant Pants documentation
pants_requirements
pants 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_requirement
target 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_development
backend to get access to thepants_requirements
target.st2/pants.toml
Line 25 in 87af527
And then use
pants_requirements
inpants-plugins/BuILD
:st2/pants-plugins/BUILD
Lines 8 to 12 in 87af527
Configure pants to find plugins in
pants-plugins/
First we add
pants-plugins
to[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-plugins
resolve 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_requirements
target, are part of thepants-plugins
resolve. aside: I also addedskip_pylint=True
like 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.lock
using./pants generate-lockfiles --resolve=pants-plugins
.pants-plugins/README.md
I also added a skeleton readme to explain what goes in the
pants-plugins/
directory.