Reputation: 52343
Every time my Python application is run, it creates a log. I want to include in that log the revision number of the code that was executed. How can I do that?
I use Python 3.2, Windows TortoiseHg 2.2.2 with Mercurial 2.0.2.
Upvotes: 2
Views: 177
Reputation: 27890
If you are using setuptools to distribute your application/package, you can access the installed package version at run time using pkg_resources.get_distribution("my_package").version
. However setuptools does not support automatic version tagging with mercurial revisions, so you will have to build your distributions with commands like:
python3 setup.py egg_info -b -$(hg heads --template "{node|short}" `hg branch`) sdist
or
python3 setup.py egg_info -b -$(hg heads --template "{node|short}" `hg branch`) setup
Upvotes: 2