Best practice for making a project aware of its own branch name and revision number

John Arbash Meinel john at arbash-meinel.com
Thu Sep 21 17:13:23 BST 2006


Charles Duffy wrote:
> So -- I have a piece of software which is revision controlled in bzr. I
> want to be able to include a branch name and build number in the
> --version output from this tool -- how can I best do that?
> 
> Having a script which runs as part of setup.py (and at startup when
> running out of the source tree) which creates a module (something like
> version.py) containing the relevant variables (such that this module and
> its contents can be imported if available) probably seems most
> reasonable. Obviously, error handling will need to be available for the
> case when the module isn't available or the script is running but bzr
> isn't installed, but that's trivial enough.
> 
> ...but if there's a better approach that I'm missing, I'm not about to
> turn away any suggestions.

As mentioned, there is my 'version-info' plugin, which I personally use.
 I'm not positive if the latest version works with all bzr versions, but
it certainly should work for new ones. (And you can revert to revno 19
if you have problems with an earlier bzr).

I personally do something like:

bzr version-info --format=python --check-clean  > library/_version.py

And then in library/__init__.py I have:

try:
  from library._version import version_info
except ImportError:
  version_info = {'revision_id': '<unknown>'
		 ... # whatever defaults you need
		 }


Some people want really details version information, so you *can* use
'bzr version-info --all' which includes the last-modified version of
every file, and the complete revision log along with commit time and
commit message.

I've also used it for C++ projects, only there I have have another
script layered on top of 'bzr version-info' because it has to process
things into C/C++ variables. And then I write out a version.h and
version.cpp, etc.
It would be possible for this to be one of the version-info default
formats, except in C++ you have to work a lot harder to avoid namespace
collisions, since each file isn't its own namespace like in python.

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060921/f1add4f1/attachment.pgp 


More information about the bazaar mailing list