This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathget_version
executable file
·82 lines (68 loc) · 2.57 KB
/
get_version
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
#!/usr/bin/env python3
# Copyright 2016, 2017 Intel Corporation
#
# 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.
# ------------------------------------------------------------------------------
import os
import subprocess
import sys
top_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
version_file = top_dir + "/VERSION"
with open(version_file, 'r') as f:
version_data = f.read().strip()
def bump_version(version):
(major, minor, patch) = version.split('.')
if 'rc' in patch:
parts = patch.split('rc')
parts[1] = str(int(parts[1]) + 1)
patch = "rc".join(parts)
else:
patch = str(int(patch) + 1)
return ".".join([major, minor, patch])
def auto_version(default, strict):
output = subprocess.check_output(['git', 'describe', '--dirty'])
parts = output.decode('utf-8').strip().split('-', 3)
parts[0] = parts[0][1:] # strip the leading 'v'
if len(parts) > 1:
parts[0] = bump_version(parts[0])
if default != parts[0]:
msg = "VERSION file and (bumped?) git describe versions differ: " \
"{} != {}".format(default, parts[0])
if strict:
print("ERROR: " + msg, file=sys.stderr)
sys.exit(1)
else:
print("WARNING: " + msg, file=sys.stderr)
parts[0] = default
if len(parts) > 1:
parts[0] = "-dev".join([parts[0], parts[1].replace("-", ".")])
if len(parts) == 4:
parts[0] = parts[0] + "-" + parts[3]
return parts[0]
else:
return parts[0]
def version(default):
if 'VERSION' in os.environ:
if os.environ['VERSION'] == 'AUTO_STRICT':
version = auto_version(default, strict=True)
elif os.environ['VERSION'] == 'AUTO':
version = auto_version(default, strict=False)
else:
version = os.environ['VERSION']
else:
version = default + "-dev1"
if 'CARGO_ARGS' in os.environ:
if "experimental" in os.environ['CARGO_ARGS']:
version = version + "-experimental"
return version
print(version(version_data))