forked from mskcc/ACCESS-Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
71 lines (51 loc) · 1.75 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
# (Taken from Toil version.py)
def version():
"""
A version identifier that includes the full-legth commit SHA1 and an optional suffix to
indicate that the working copy is dirty.
"""
return _version()
def short_version():
"""
A version identifier that includes the abbreviated commit SHA1 and an optional suffix to
indicate that the working copy is dirty.
"""
return _version(shorten=True)
def _version(shorten=False):
return '-'.join(filter(None, [current_commit()[:7 if shorten else None],
('dirty' if dirty() else None)]))
def most_recent_tag():
import subprocess
return subprocess.check_output(["git", "describe", "--tags"]).strip()
def current_commit():
from subprocess import check_output
try:
output = check_output('git log --pretty=oneline -n 1 -- $(pwd)', shell=True).split()[0]
except:
# Return this if we are not in a git environment.
return 'no_git_dir'
return output
def dirty():
from subprocess import call
try:
return 0 != call('(git diff --exit-code '
'&& git diff --cached --exit-code) > /dev/null', shell=True)
except:
return False # In case the git call fails.
def expand_(name=None):
variables = {k: v for k, v in globals().items()
if not k.startswith('_') and not k.endswith('_')}
def resolve(k):
v = variables[k]
if callable(v):
v = v()
return v
if name is None:
return ''.join("%s = %s\n" % (k, repr(resolve(k))) for k, v in variables.items())
else:
return resolve(name)
def _main():
import sys
sys.stdout.write(expand_(*sys.argv[1:]))
if __name__ == '__main__':
_main()