1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 SETUP_DIR = os.path.dirname(__file__) or '.'
13 gittags = subprocess.check_output(['git', 'tag', '-l']).split()
14 gittags.sort(key=lambda s: [int(u) for u in s.split(b'.')],reverse=True)
15 return str(next(iter(gittags)).decode('utf-8'))
17 def choose_version_from():
18 sdk_ts = subprocess.check_output(
19 ['git', 'log', '--first-parent', '--max-count=1',
20 '--format=format:%ct', os.path.join(SETUP_DIR, "../python")]).strip()
21 cwl_ts = subprocess.check_output(
22 ['git', 'log', '--first-parent', '--max-count=1',
23 '--format=format:%ct', SETUP_DIR]).strip()
24 if int(sdk_ts) > int(cwl_ts):
25 getver = os.path.join(SETUP_DIR, "../python")
30 def git_timestamp_tag():
31 gitinfo = subprocess.check_output(
32 ['git', 'log', '--first-parent', '--max-count=1',
33 '--format=format:%ct', choose_version_from()]).strip()
34 return str(time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo))))
36 def save_version(setup_dir, module, v):
37 with open(os.path.join(setup_dir, module, "_version.py"), 'w') 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"), 'r') 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_latest_tag() + git_timestamp_tag())
52 except (subprocess.CalledProcessError, OSError):
55 return read_version(setup_dir, module)