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, "../python")),
15 os.path.abspath(os.path.join(SETUP_DIR, "../../tools/crunchstat-summary")),
16 os.path.abspath(os.path.join(SETUP_DIR, "../../build/version-at-commit.sh"))
19 def choose_version_from():
21 for path in VERSION_PATHS:
22 ts[subprocess.check_output(
23 ['git', 'log', '--first-parent', '--max-count=1',
24 '--format=format:%ct', path]).strip()] = path
26 sorted_ts = sorted(ts.items())
27 getver = sorted_ts[-1][1]
28 print("Using "+getver+" for version number calculation of "+SETUP_DIR, file=sys.stderr)
31 def git_version_at_commit():
32 curdir = choose_version_from()
33 myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent',
34 '--format=%H', curdir]).strip()
35 myversion = subprocess.check_output([SETUP_DIR+'/../../build/version-at-commit.sh', myhash]).strip().decode()
38 def save_version(setup_dir, module, v):
39 v = v.replace("~dev", ".dev").replace("~rc", "rc")
40 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
41 return fp.write("__version__ = '%s'\n" % v)
43 def read_version(setup_dir, module):
44 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
45 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
47 def get_version(setup_dir, module):
48 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
51 save_version(setup_dir, module, env_version)
54 save_version(setup_dir, module, git_version_at_commit())
55 except (subprocess.CalledProcessError, OSError) as err:
56 print("ERROR: {0}".format(err), file=sys.stderr)
59 return read_version(setup_dir, module)
61 # Called from calculate_python_sdk_cwl_package_versions() in run-library.sh
62 if __name__ == '__main__':
63 print(get_version(SETUP_DIR, "arvados_cwl"))