enough-painting-56758
09/12/2025, 8:01 AMapplication/
src/
service_a/
BUILD
service_b/
BUILD
pants.toml
pyproject.toml
Each BUILD file currently looks like this:
# Include all Python source files in this directory
python_sources()
# Define a Docker image target
docker_image(
image_tags=["latest"],
name="docker_image",
repository="service_a",
)
# Define a PEX (Python Executable) binary target
pex_binary(
name="app",
entry_point="app.py",
)
Right now I’m pushing Docker images with the latest tag using this command:
pants --changed-since=origin/main --changed-dependents=transitive list publish
I’d like to generate independent semantic versions for each service.
To do that, I added a vcs_version target in each service’s BUILD file:
# Generate service-specific version
vcs_version(
generate_to="src/service_a/version.py",
name="version",
template="__version__ = '{version}'",
)
This creates a version.py file per service.
My questions are:
• How do I tag the Docker image with this generated version?
• Will this setup automatically produce an independent version for each service based on changes in that service only?
Thanks in advance for any help!enough-painting-56758
09/29/2025, 7:14 AMmammoth-dawn-85816
09/29/2025, 7:36 AMBUILD files are python.
Your vcs_version line above generates a file with the version in it (which will be in the form "0.1.dev244+g22ac66c.d20250929" which, I assume, you can extract the version number details from the front of?).
So you might be able to:
• Create a python “labeller.py” file which imports the version.py you’ve created (dynamically, as an argument), then outputs a list of the versions you’d want to tag with (eg. ["latest", "v0", "v0.1"] or whatever)
• Then import “labeller” in your BUILD, and then call your new function: docker_image(image_tags=labeller.process("./version"), dependencies=[":version"]…)
This may be entirely wrongheaded, but I figure something is useful to experiment with, even if it isn’t right! I hope this helps?enough-painting-56758
09/29/2025, 9:24 AMlabeller.process("./version") It isn’t possible directly within a BUILD file.mammoth-dawn-85816
09/29/2025, 9:25 AMenough-painting-56758
11/14/2025, 12:39 PMdazzling-pizza-75442
11/14/2025, 1:40 PMenough-painting-56758
11/14/2025, 3:14 PMgit describe to detect changes, because we need independent versioning for each service—even when the changes come from shared modules or other dependencies. Instead, we want to use Pants to identify the impacted services with:
pants --changed-since=origin/main --changed-dependents=transitive list
This way, we only bump the version of a service if it has actually changed or is affected by a change.wide-midnight-78598
11/15/2025, 12:57 AMwide-midnight-78598
11/15/2025, 12:59 AM