forked from DataBiosphere/toil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_template.py
153 lines (118 loc) · 4.64 KB
/
version_template.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (C) 2015-2018 Regents of the University of California
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This script is a template for src/toil/version.py. Running it without arguments echoes all
globals, i.e. module attributes. Constant assignments will be echoed verbatim while callables
will be invoked and their result echoed as an assignment using the function name as the left-hand
side and the return value of the function as right-hand side. To prevent a module attribute from
being echoed, start or end the attribute name with an underscore. To print the value of a single
symbol, pass the name of that attribute to the script as a command line argument. You can also
import the expand_ function and invoke it directly with either no or exactly one argument."""
# Note to maintainers:
#
# - don't import at module level unless you want the imported value to be included in the output
# - only import from the Python standard run-time library (you can't have any dependencies)
baseVersion = '3.22.0a1'
cgcloudVersion = '1.6.0a1.dev393'
dockerName = 'toil'
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 shortVersion():
"""
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, [distVersion(),
currentCommit()[:7 if shorten else None],
('dirty' if dirty() else None)]))
def distVersion():
"""
The distribution version identifying a published release on PyPI.
"""
from pkg_resources import parse_version
build_number = buildNumber()
parsedBaseVersion = parse_version(baseVersion)
if isinstance(parsedBaseVersion, tuple):
raise RuntimeError("Setuptools version 8.0 or newer required. Update by running "
"'pip install setuptools --upgrade'")
if build_number is not None and parsedBaseVersion.is_prerelease:
return baseVersion + '.dev' + build_number
else:
return baseVersion
def dockerTag():
"""
The primary tag of the Docker image for the appliance. This uniquely identifies the appliance
image.
"""
return version()
def dockerShortTag():
"""
A secondary, shortened form of :func:`dockerTag` with which to tag the appliance image for
convenience.
"""
return shortVersion()
def dockerMinimalTag():
"""
A minimal tag with which to tag the appliance image for convenience. Does not include
information about the git commit or working copy dirtyness.
"""
return distVersion()
def buildNumber():
"""
The Jenkins build number, if defined, else None.
"""
import os
return os.getenv('BUILD_NUMBER')
def currentCommit():
from subprocess import check_output
try:
output = check_output('git log --pretty=oneline -n 1 -- $(pwd)', shell=True).decode('utf-8').split()[0]
except:
# Return this we are not in a git environment.
return '000'
if isinstance(output, bytes):
return output.decode('utf-8')
return str(output)
def dockerRegistry():
import os
return os.getenv('TOIL_DOCKER_REGISTRY', 'quay.io/ucsc_cgl')
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()