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