1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
13 os.path.abspath(os.path.join(SETUP_DIR, "../../build/version-at-commit.sh"))
16 def choose_version_from():
18 for path in VERSION_PATHS:
19 ts[subprocess.check_output(
20 ['git', 'log', '--first-parent', '--max-count=1',
21 '--format=format:%ct', path]).strip()] = path
23 sorted_ts = sorted(ts.items())
24 getver = sorted_ts[-1][1]
25 print("Using "+getver+" for version number calculation of "+SETUP_DIR)
28 def git_version_at_commit():
29 curdir = choose_version_from()
30 myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent',
31 '--format=%H', curdir]).strip()
32 myversion = subprocess.check_output([SETUP_DIR+'/../../build/version-at-commit.sh', myhash]).strip().decode()
35 def save_version(setup_dir, module, v):
36 v = v.replace("~dev", ".dev").replace("~rc", "rc")
37 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
38 return fp.write("__version__ = '%s'\n" % v)
40 def read_version(setup_dir, module):
41 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
42 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
44 def get_version(setup_dir, module):
45 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
48 save_version(setup_dir, module, env_version)
51 save_version(setup_dir, module, git_version_at_commit())
52 except (subprocess.CalledProcessError, OSError) as err:
53 print("ERROR: {0}".format(err))
56 return read_version(setup_dir, module)