1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
11 gitinfo = subprocess.check_output(
12 ['git', 'describe', '--abbrev=0']).strip()
13 return str(gitinfo.decode('utf-8'))
15 def git_timestamp_tag():
16 gitinfo = subprocess.check_output(
17 ['git', 'log', '--first-parent', '--max-count=1',
18 '--format=format:%ct', '.']).strip()
19 return str(time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo))))
21 def save_version(setup_dir, module, v):
22 with open(os.path.join(setup_dir, module, "_version.py"), 'w') as fp:
23 return fp.write("__version__ = '%s'\n" % v)
25 def read_version(setup_dir, module):
26 with open(os.path.join(setup_dir, module, "_version.py"), 'r') as fp:
27 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
29 def get_version(setup_dir, module):
30 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
33 save_version(setup_dir, module, env_version)
36 save_version(setup_dir, module, git_latest_tag() + git_timestamp_tag())
37 except subprocess.CalledProcessError:
40 return read_version(setup_dir, module)