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, "../../sdk/python")),
15 os.path.abspath(os.path.join(SETUP_DIR, "../../build/version-at-commit.sh"))
18 def choose_version_from():
20 for path in VERSION_PATHS:
21 ts[subprocess.check_output(
22 ['git', 'log', '--first-parent', '--max-count=1',
23 '--format=format:%ct', path]).strip()] = path
25 sorted_ts = sorted(ts.items())
26 getver = sorted_ts[-1][1]
27 print("Using "+getver+" for version number calculation of "+SETUP_DIR, file=sys.stderr)
30 def git_version_at_commit():
31 curdir = choose_version_from()
32 myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent',
33 '--format=%H', curdir]).strip()
34 myversion = subprocess.check_output([SETUP_DIR+'/../../build/version-at-commit.sh', myhash]).strip().decode()
37 def save_version(setup_dir, module, v):
38 v = v.replace("~dev", ".dev").replace("~rc", "rc")
39 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
40 return fp.write("__version__ = '%s'\n" % v)
42 def read_version(setup_dir, module):
43 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
44 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
46 def get_version(setup_dir, module):
47 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
50 save_version(setup_dir, module, env_version)
53 save_version(setup_dir, module, git_version_at_commit())
54 except (subprocess.CalledProcessError, OSError) as err:
55 print("ERROR: {0}".format(err), file=sys.stderr)
58 return read_version(setup_dir, module)