1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 def git_version_at_commit():
11 curdir = os.path.dirname(os.path.abspath(__file__))
12 myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent',
13 '--format=%H', curdir]).strip()
14 myversion = subprocess.check_output([curdir+'/../../build/version-at-commit.sh', myhash]).strip().decode()
17 def save_version(setup_dir, module, v):
18 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
19 return fp.write("__version__ = '%s'\n" % v)
21 def read_version(setup_dir, module):
22 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
23 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
25 def get_version(setup_dir, module):
26 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
29 env_version = env_version.replace("~rc", "rc")
30 save_version(setup_dir, module, env_version)
33 save_version(setup_dir, module, git_version_at_commit())
34 except (subprocess.CalledProcessError, OSError):
37 return read_version(setup_dir, module)