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 v = v.replace("~dev", ".dev").replace("~rc", "rc")
19 with open(os.path.join(setup_dir, module, "_version.py"), 'wt') as fp:
20 return fp.write("__version__ = '%s'\n" % v)
22 def read_version(setup_dir, module):
23 with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp:
24 return re.match("__version__ = '(.*)'$", fp.read()).groups()[0]
26 def get_version(setup_dir, module):
27 env_version = os.environ.get("ARVADOS_BUILDING_VERSION")
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)