Hi, I've found such entry on Pants webpage: ```Som...
# plugins
e
Hi, I've found such entry on Pants webpage:
Copy code
Some example plugins that users have written:
Custom setup.py logic to compute the version dynamically
It can help me a lot. Does maybe someone have this plugin with setup.py and could share? I will be grateful. Thank You in advance.
h
Hey Łukasz, welcome! https://www.pantsbuild.org/docs/plugins-setup-py is the guide for this It links to an internal plugin we use for Pants to set the
version
from a
VERSION
file. I believe @narrow-activity-17405 wrote a plugin that behaves similarly. @full-oyster-41619 wrote a plugin that runs Git, but it uses lots of Git utilities they already had, so I’m not sure how shareable it would be. -- What are you hoping to achieve with your plugin?
e
Generally I would like to have
version
in setup.py in every package from some package file like
__init__.py
defined on package level. The same with
long_description
for example from
README.rst
. I've just started with Pants I read almost all docs here. This solution contains global
README
not individual for each package. I will try maybe I will handle it and create something. Thanks :)
Something like ``requirements.txt` file and
python_requirements()
.
Btw thanks for very quick reply.
❤️ 1
h
Cool, that approach will be similar to the example Pants plugin, but you’ll also use some of the information from the
target_type
to be able to locate which README and
__init__.py
to use. For example, you could look at the “address” for the
python_distribution
target and compute the files to read from there. Do you know what assumptions you’d be able to make for where those two files will live for each distinct
python_distribution
you have? For example:
The
README
will always in the same directory of the `python_distribution`’s BUILD file
vs
I have two top-level READMEs in my organization, and each project decides which of the two they want
I’m trying to figure out the best way to model what you’re after in your plugin.
e
Ok I think the advice with
target_type
can help me. I think I will have
README
always with
python_distibution
. I will try and play a little with Pants. It will be always a good challenge 🙂
h
I think I will have README always with python_distibution
Cool, so you can use
request.target.address.spec_path
in your
@rule
to dynamically get the parent directory of your
BUILD
file. Then, use
await Get(DigestContents, PathGlobs([os.path.join(parent_dir, "README.rst"])
to use the engine to read the README.rst file from the file system. I recommend taking this approach: 1. Implement the example in that guide that simply hardcodes a kwarg. Get that working, so that you know all your
register.py
setup and everything is working. 2. Add the logic to set
long_description
from a
README
. 3. Figure out what semantics you want for setting the
version
, e.g. reading from
__init__.py
vs.
VERSION
Treat each step as a distinct milestone. It can get confusing if you try to do everything all at once.
It will be always a good challenge 🙂
That being said, please do not hesitate to ask for help! The plugin docs are only in their first iteration. We know from a couple other plugin authors that we want to do a rewrite of them to be more helpful. It’s totally okay if things don’t make sense right away. These concepts can be hard to make sense of at first, and we know we can do a better job explaining them. No need to suffer trying to figure something out - we’re happy to help 🙂
e
Ohh Thanks! I tried already with
await Get
but I have problem with parent directory. This ``request.target.address.spec_path`` should definitely help me 🙂 Thanks for help one more time! 🙂
❤️ 1
h
Feel free to share your work in progress over Slack or as a Gist btw! We’re always happy to do code reviews (and it’s useful feedback for us about how we can improve the Plugin API and docs)
e
Ok I will 🙂 I think I will try later also to create goal to bump version with proper changelog. If I do it I will share it maybe it will be useful for someone else. Thanks! :)
👍 1
f
I can share my versioning utility based on git semver versioning if it helps