-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
Add pants-plugins/release
to handle wheel metadata generation
#5891
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
cognifloyd
requested review from
winem,
arm4b,
nzlosh,
rush-skills,
amanda11 and
a team
February 6, 2023 23:10
pull-request-size
bot
added
the
size/XL
PR that changes 500-999 lines. Consider splitting work into several ones that easier to review.
label
Feb 6, 2023
cognifloyd
commented
Feb 6, 2023
@@ -72,7 +72,7 @@ | |||
"Repository": "https://github.com/StackStorm/st2", | |||
"Documentation": "https://docs.stackstorm.com", | |||
"Community": "https://stackstorm.com/community-signup", | |||
"Questions": "https://forum.stackstorm.com/", | |||
"Questions": "https://github.com/StackStorm/st2/discussions", |
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.
I also noticed that this URL in our old st2client/setup.py
file was out-of date. Ideally we won't be using this setup.py file, but I went ahead and updated it here as well.
rush-skills
approved these changes
Feb 7, 2023
cognifloyd
force-pushed
the
pants-plugins-release
branch
from
February 8, 2023 18:58
0080336
to
176dc53
Compare
Rebased and added |
amanda11
approved these changes
Feb 9, 2023
cognifloyd
removed this pull request from the merge queue due to the queue being cleared
Feb 9, 2023
cognifloyd
force-pushed
the
pants-plugins-release
branch
from
February 9, 2023 20:36
176dc53
to
ffe174b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
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
Generally, wheels have a
setup.py
file in them. Right now, we have hard-codedsetup.py
and a copy ofdist_utils.py
. These are spread out, and no one likes maintaining them. But, using pants, this becomes much easier.Pants can auto-generate a
setup.py
for us whenever it builds apython_distribution()
(ie a wheel or an sdist). And, pants makes it easy to centralize all of the common bits of metadata that need to go in all the wheels (likeauthor="StackStorm"
or ourproject_urls
). This PR addspants-plugins/release
to take advantage of those features.python_distribution()
targetsThis PR does not actually create the
python_distribution()
targets yet--that will happen in a follow-up PR. But, here is what a python_distribution looks like with some common options we will use:Pants generates
setup.py
Everything in
provides=python_artifact(...)
becomes the keyword args that pants puts in the call tosetup(...)
in the generatedsetup.py
file.setup(...)
also gets kwargs from a few other places including theentry_points=
kwarg of python_distribution, and a special plugin rule:st2/pants-plugins/release/rules.py
Lines 88 to 89 in 2266086
NB: Only one plugin can provide the
SetupKwargs
.To wire up this rule, I created a
StackStormSetupKwargsRequest
class, and wired it up with aUnionRule
:st2/pants-plugins/release/rules.py
Line 165 in 2266086
That way, whenever pants goes to generate
setup.py
, it will use our plugins to inject additional kwargs in thesetup(...)
call ofsetup.py
.Dynamically retrieving
version
andlong_description
kwargsIn our current
setup.py
+dist_utils.py
setup, we retrieve theversion
kwarg from an__init__.py
file like this (or for st2client we actually just import__version__
from the__init__.py
file):st2/st2common/setup.py
Line 36 in 2266086
The
get_version_string
function is defined indist_utils.py
:st2/st2common/dist_utils.py
Lines 163 to 174 in 2266086
So, we do something very similar in this plugin. The BUILD file specifies a
version_file
arg onpython_artifact(...)
, to say which__init__.py
file to use. Then the plugin gets the contents of the file and extracts the version string, just like theget_version_string
function from our olddist_utils.py
file.NB: The
glob_match_error_behavior=GlobMatchErrorBehavior.error
bit means that if the version_file does not exist, an error will be raised when attempting to build the wheel.st2/pants-plugins/release/rules.py
Lines 100 to 108 in 2266086
st2/pants-plugins/release/rules.py
Lines 118 to 125 in 2266086
In our current
setup.py
for thest2client
wheel, we also include aREADME.rst
file in thelong_description
kwarg. So, we do the same thing in this plugin as well:st2/pants-plugins/release/rules.py
Lines 109 to 115 in 2266086
st2/pants-plugins/release/rules.py
Lines 132 to 137 in 2266086
Centralized Wheel Metadata
And finally, we also define the metadata that is common to all of our wheels here:
st2/pants-plugins/release/rules.py
Lines 37 to 66 in 2266086
Note that the classifiers get combined like this:
st2/pants-plugins/release/rules.py
Lines 151 to 157 in 2266086
That means that the python version classifiers are also included. As the TODO says, we still need to pull out the versions from the
interpreter_constraints
--until then, we've just got them hard-coded.Developing pants plugins
Pants has extensive documentation on the plugin API, including how to create targets, how to write rules, and there's even a mini tutorial about how to add a formatter (adding formatters is a very common thing for plugins to do).
python_distribution()
targetpython_artifact()
kwargs