Search code examples
pythonbazaar

Have program report bazaar revision number when run


I have a python program under bazaar version control. How can I get the program to display the current branch revision number and date/build-date when run? The program is exported, not executed from a working copy tree.

There is a svn version of this question at Getting SVN revision number into a program automatically


Solution

  • Ok, I get it, adding a build step, or more precisely something to the export process in this case, to stamp some revision info is the only way to go (as I've been told before in the context of Mercurial. I guess I'm thick and a slow learner :-)

    So building on both jcollado and wal-o-mat's answsers with some stuff I learned elsewhere, here is the approach I'll use:

    At export time generate current revision info (in command shell, I could get wal-o-mat's subprocess to work on on of my computers but not the another):

    bzr version-info --python > bzr_version.py
    

    At run-time read and report from the file generated above:

    import bzr_version
    d = bzr_version.version_info
    build = d.get('revno','<unknown revno>')
    date  = d.get('build_date','<unknown build date>')