--version Support In A Python Program Built With Pants
How can I get Pants to store the output of git describe somewhere in my .pex file so that I can access it from the Python code I'm writing? Basically I want to be able to clone my
Solution 1:
Turns out pex
already does git describe
on build. The result it stores in a PEX-INFO
file in the root of the .pex
file. So to read it, I did this:
defget_version():
"""Extract version string from PEX-INFO file"""
my_pex_name = os.path.dirname(__file__)
zip = zipfile.ZipFile(my_pex_name)
withzip.open("PEX-INFO") as pex_info:
return json.load(pex_info)['build_properties']['tag']
This is good enough IMO, but there are also drawbacks. If somebody has an improved answer I'm prepared to switch to that one as the accepted one.
Outages with this one:
- Relies on relative paths to locate
PEX-INFO
, would be better if there was some kind of API call for this. - No way to customize how the version number is computed; I'd like to do
git describe --dirty
for example.
Post a Comment for "--version Support In A Python Program Built With Pants"