breezy-mouse-20493
12/04/2023, 11:45 PMpants package
-- is to add a text resource
that has a version string inside it. (It's not something that I want to do long term, but it has gotten me this far...).
Today I'm looking at the pants package
goal and have added this to the build file:
python_sources(
dependencies=[":version"]
)
resource(
# Adding a version file as a package resource
name="version",
source="VERSION"
)
python_distribution(
name="dist",
...
provides=python_artifact(
...
# Adding a version here too, as required by `provides=`?
version="1.2.3+what",
),
)
So now I have two ways of declaring a package version. And two ways of inspecting the version at runtime.
In the first version, I am able do version = pkgutil.get_data(__name__, "VERSION").decode().strip()
from the python runtime to get the package version using the text file. On the other hand, this is not guaranteed to coincide with the package metadata's notion of a version, which is given by the provides
argument of python_distribution
Which versioning mechanism is correct? Also, what alternatives exist?
As for why we want to inspect the package version at runtime: Some of our CLI tools provide a --version option, and to accomplish this we inspect the package version and echo that back to the user in the terminal.breezy-mouse-20493
12/05/2023, 1:08 AMbreezy-mouse-20493
12/05/2023, 1:09 AM