-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_updateversion.py
More file actions
33 lines (22 loc) · 950 Bytes
/
_updateversion.py
File metadata and controls
33 lines (22 loc) · 950 Bytes
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
#!/usr/bin/env/python
# coding=utf-8
import os
import subprocess
_HERE = os.path.abspath(os.path.dirname(__file__))
def updateversion(path=_HERE):
# Fetch version from git tags, and write to version.py
# Also, when git is not available (PyPi package), use stored version.py
version_py = os.path.join(path, 'cabling', 'version.py')
try:
version_git = subprocess.check_output(
["git", "describe"]
).rstrip().decode()
except subprocess.CalledProcessError:
with open(version_py, 'r') as fh:
version_git = fh.read().strip().split("=")[-1].replace("'", '')
version_git = version_git.lower().replace('v', '').replace(' ', '')
version_msg = "# Do not edit, pipeline versioning governed by git tags!"
with open(version_py, "w") as fh:
msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git)
fh.write(version_msg + msg)
return version_git