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__))
12 def choose_version_from():
13 sdk_ts = subprocess.check_output(
14 ['git', 'log', '--first-parent', '--max-count=1',
15 '--format=format:%ct', os.path.join(SETUP_DIR, "../../sdk/python")]).strip()
16 cwl_ts = subprocess.check_output(
17 ['git', 'log', '--first-parent', '--max-count=1',
18 '--format=format:%ct', SETUP_DIR]).strip()
19 if int(sdk_ts) > int(cwl_ts):
20 getver = os.path.join(SETUP_DIR, "../../sdk/python")
25 def git_version_at_commit():
26 curdir = choose_version_from()
27 myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent',
28 '--format=%H', curdir]).strip()
29 myversion = subprocess.check_output([curdir+'/../../build/version-at-commit.sh', myhash]).strip().decode()
32 def save_version(setup_dir, module, v):
33 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
34 return fp.write("__version__ = '%s'\n" % v)
36 def read_version(setup_dir, module):
37 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
38 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
40 def get_version(setup_dir, module):
41 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
44 save_version(setup_dir, module, env_version)
47 save_version(setup_dir, module, git_version_at_commit())
48 except (subprocess.CalledProcessError, OSError):
51 return read_version(setup_dir, module)