-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_tools.py
40 lines (35 loc) · 859 Bytes
/
git_tools.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
"""Routines to work with git data."""
# core python packaes
import re
import subprocess
# third party packages
# custom packages
def version_from_tag():
"""
Parse 'git describe --tags' and return a version.
:return: (string) Version.
"""
cmd = [
'git',
'describe',
'--tags',
'--match',
'v*',
'--long',
'--dirty'
]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()
stdout = stdout.decode('utf-8').rstrip('\n')
version = stdout
version = version.replace('-dirty', '+dirty')
version = re.sub(r'-g(\w{7})', '', version)
version = re.sub(r'-(\d+)', r'.post\1', version)
# remove the leading 'v'
return version[1:]
if __name__ == '__main__':
pass