-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversion.py
38 lines (28 loc) · 962 Bytes
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import subprocess
# The Major.Minor version of the app
BASE_VERSION = "0.0"
# Calculate the commit count and use it as a build number
proc = subprocess.Popen(
'git fetch --unshallow origin; '
'git rev-list --count origin/`git rev-parse --abbrev-ref HEAD`',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = proc.communicate()
commitCount = int(stdout.strip(), 10)
versionNumber = "{}.{}".format(BASE_VERSION, commitCount)
# Update the build number in the setup.py file
dirName = os.path.dirname(__file__)
setupFile = os.path.join(dirName, 'setup.py')
with open(setupFile, 'r') as infile:
setupFileData = infile.readlines()
for i, line in enumerate(setupFileData):
if not line.startswith('version = '):
continue
setupFileData[i] = "version = '{}'\n".format(versionNumber)
break
with open(setupFile, 'w') as outfile:
outfile.writelines(setupFileData)
print(versionNumber)