forked from python-control/python-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_version.py
40 lines (32 loc) · 1.27 KB
/
make_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
39
40
from subprocess import check_output
import os
def main():
cmd = 'git describe --always --long'
output = check_output(cmd.split()).decode('utf-8').strip().split('-')
if len(output) == 3:
version, build, commit = output
else:
raise Exception("Could not git describe, (got %s)" % output)
print("Version: %s" % version)
print("Build: %s" % build)
print("Commit: %s\n" % commit)
filename = "control/_version.py"
print("Writing %s" % filename)
with open(filename, 'w') as fd:
if build == '0':
fd.write('__version__ = "%s"\n' % (version))
else:
fd.write('__version__ = "%s.post%s"\n' % (version, build))
fd.write('__commit__ = "%s"\n' % (commit))
# Write files for conda version number
SRC_DIR = os.environ.get('SRC_DIR', '.')
conda_version_path = os.path.join(SRC_DIR, '__conda_version__.txt')
print("Writing %s" % conda_version_path)
with open(conda_version_path, 'w') as conda_version:
conda_version.write(version)
conda_buildnum_path = os.path.join(SRC_DIR, '__conda_buildnum__.txt')
print("Writing %s" % conda_buildnum_path)
with open(conda_buildnum_path, 'w') as conda_buildnum:
conda_buildnum.write(build)
if __name__ == '__main__':
main()