This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
forked from python-control/python-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_version.py
58 lines (53 loc) · 2.2 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# make_version.py - generate version information
#
# Author: Clancy Rowley
# Date: 2 Apr 2015
# Modified: Richard M. Murray, 28 Dec 2017
#
# This script is used to create the version information for the python-
# control package. The version information is now generated directly from
# tags in the git repository. Now, *before* running setup.py, one runs
#
# python make_version.py
#
# and this generates a file with the version information. This is copied
# from binstar (https://github.com/Binstar/binstar) and seems to work well.
#
# The original version of this script also created version information for
# conda, but this stopped working when conda v3 was released. Instead, we
# now use jinja templates in conda-recipe to create the conda information.
# The current version information is used in setup.py, control/__init__.py,
# and doc/conf.py (for sphinx).
from subprocess import check_output
import os
def main():
cmd = 'git describe --always --long'
# describe --long usually outputs "tag-numberofcommits-commitname"
output = check_output(cmd.split()).decode('utf-8').strip().rsplit('-',2)
if len(output) == 3:
version, build, commit = output
else:
# If the clone is shallow, describe's output won't have tag and
# number of commits. This is a particular issue on Travis-CI,
# which by default clones with a depth of 50.
# This behaviour isn't well documented in git-describe docs,
# but see, e.g., https://stackoverflow.com/a/36389573/1008142
# and https://github.com/travis-ci/travis-ci/issues/3412
version = 'unknown'
build = 'unknown'
# we don't ever expect just one dash from describe --long, but
# just in case:
commit = '-'.join(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))
if __name__ == '__main__':
main()