[TriZPUG] Reference The Current Version Of Your Python Egg In Your Modules

Philip Semanchuk philip at semanchuk.com
Fri Jan 24 03:29:39 CET 2014


On Jan 23, 2014, at 7:40 PM, Josh Johnson wrote:

> So I've got an app. It's packaged as an egg. I want to do stuff like write
> to the log file "starting MyApp version 1.2.3332". What's the best way to
> store that information?
> 
> In the past I've set a 'constant' at the root of the egg, something like
> APPVERSION, and I reference it as MyApp.APPVERSION. I just have to remember
> to keep it in line with the version in setup.py.
> 
> Is there a better way?

Hi Josh,
I dunno if this is quite what you are looking for, but my app packages always contain a file called VERSION which contains (surprisingly) the version string and nothing else. That's the only place the version resides; all other code reads it from there. For instance, I have this in my setup.py --

VERSION = open("VERSION").read().strip()


That value also gets compiled into my C code via a .h file (which is written by setup.py), it's used by the code that builds my tarballs, etc.

This also has the advantage of putting the version in a discrete, clearly marked file so that someone can see the package version even if its directory name (which typically contains the version info) gets changed.

Hope this helps,
Philip



More information about the TriZPUG mailing list