:wave: Hi! I'm learning :pants: and would like to ...
# general
b
👋 Hi! I'm learning 👖 and would like to use it with the Polylith architecture (I'm the maintainer of the Python tooling for that). I think they will fit really well together. I'm trying to understand how code sharing is setup in Pants: I have all my code in a shared top namespace (tried accessing the code with
pants repl ::
and that worked nicely), and would like to build different artifacts (wheels) based on a subset of the shared code. Currently (with poetry, hatch, pdm or rye), I have the definitions in a
pyproject.toml
file for each thing to build. I guess it is different when using 👖 . How do I specify that the artifact 1 need these namespace packages, and artifact 2 those other ones? I have no code where the configs are, all code is in the shared top folder. Is that possible to do with Pants?
The code examples I've found have python code in the different apps/services/artifacts, and importing from a shared package. But I wonder if it is possible to only have a configuration (pyproject.toml or maybe a BUILD file) only?
With definitions in the pyproject.toml file, I mean the source code and not the third-party dependencies (that part I think I am beginning to understand how it is setup in Pants). Basically, how to specify the entry point (that also is located in a folder at the root).
d
You can do
pants run path/to/your/entrypoint.py
. For the dependencies, Pants reads your import statements and resolves everything by itself.
🙏 1
b
Thanks! That's very useful information. If I want to build a wheel based on that entry point, how would I do that?
d
Haven't ever done that myself, but I guess you'll need
python_distribution
in one of yours BUILD files. https://www.pantsbuild.org/2.20/docs/python/goals/package#create-a-setuptools-distribution
h
Hi @busy-piano-29318! Pants was indeed designed for deploying multiple "things" (binaries, wheels, jars, docker images, etc.) from a single shared repo.
And @dry-architect-80370 is correct,
python_distribution
is how you tell Pants about a wheel you want it to build
You can either provide your own setup.py/setup.cfg/pyproject.toml/whatever the currently popular build config flavor is, or you can let Pants generate it based on the metadata it knows about.
You can have multiple
python_distribution
targets in a single BUILD file, or scatter them throughout the codebase, whatever makes sense for your repo layout
b
Thank you @happy-kitchen-89482 and @dry-architect-80370 - I’ll try this out!
h
That docs page is worth reading carefully, it's a little nuanced
b
I probably read it too fast and skipped (missed) the essential parts. Got eager to learn about Pants 😄
h
It's non-trivial, I admit
Python was not designed for "single repo, multiple outputs". Its tooling fundamentally expects a single top-level thing. So a lot of the logic in the Pants Python backend is tricking Python into its comfort zone...
Or out of its comfort zone, I suppose...
b
Yes, I recognize that when developing the tooling for Polylith 😄