1
2
3
4
5
6 import os
7
8 version = "latest"
9
10 try:
11 fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'VERSION')
12 version = open(fn).read().strip()
13
14 except IOError:
15 from subprocess import Popen, PIPE, STDOUT
16 import re
17
18 VERSION_MATCH = re.compile(r'\d+\.\d+\.\d+(\w|-)*')
19
20 try:
21 p = Popen(['git', 'describe', '--tags', '--always'], stdout=PIPE, stderr=STDOUT)
22 out = p.communicate()[0]
23
24 if (not p.returncode) and out:
25 v = VERSION_MATCH.search(out)
26 if v:
27 version = v.group()
28 except OSError:
29 pass
30