]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/get-version.py
setup: organize misc/ scripts and tools and remove obsolete ones
[tahoe-lafs/tahoe-lafs.git] / misc / build_helpers / get-version.py
1 #!/usr/bin/env python
2
3 """Determine the version number of the current tree.
4
5 This should be run after 'setup.py darcsver'. It will emit a single line of text
6 to stdout, either of the form '0.2.0' if this is a release tree (i.e. no patches
7 have been added since the last release tag), or '0.2.0-34' (if 34 patches have
8 been added since the last release tag). If the tree does not have a well-formed
9 version number, this will emit 'unknown'.
10
11 The version string thus calculated should exactly match the version string
12 determined by setup.py (when it creates eggs and source tarballs) and also
13 the version available in the code image when you do:
14
15  from allmydata import __version__
16
17 """
18
19 import os.path, re
20
21 def get_version():
22     VERSIONFILE = "src/allmydata/_version.py"
23     verstr = "unknown"
24     if os.path.exists(VERSIONFILE):
25         VSRE = re.compile("^verstr = ['\"]([^'\"]*)['\"]", re.M)
26         verstrline = open(VERSIONFILE, "rt").read()
27         mo = VSRE.search(verstrline)
28         if mo:
29             verstr = mo.group(1)
30         else:
31             raise ValueError("if version.py exists, it must be well-formed")
32
33     return verstr
34
35 if __name__ == '__main__':
36     verstr = get_version()
37     print verstr
38