X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d506c0c47b3bee53d89fcbb9d3b933d4b3aee39a..a82b39e1849a67854cb3399a4660b77548edd580:/sdk/cwl/arvados_version.py diff --git a/sdk/cwl/arvados_version.py b/sdk/cwl/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/sdk/cwl/arvados_version.py +++ b/sdk/cwl/arvados_version.py @@ -4,17 +4,37 @@ import subprocess import time +import os +import re -class VersionInfoFromGit(): - """Return arvados version from git - """ - def git_latest_tag(self): - gitinfo = subprocess.check_output( - ['git', 'describe', '--abbrev=0']).strip() - return str(gitinfo.decode('utf-8')) - - def git_timestamp_tag(self): - gitinfo = subprocess.check_output( - ['git', 'log', '--first-parent', '--max-count=1', - '--format=format:%ct', '.']).strip() - return str(time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))) +def git_latest_tag(): + gitinfo = subprocess.check_output( + ['git', 'describe', '--abbrev=0']).strip() + return str(gitinfo.decode('utf-8')) + +def git_timestamp_tag(): + gitinfo = subprocess.check_output( + ['git', 'log', '--first-parent', '--max-count=1', + '--format=format:%ct', '.']).strip() + return str(time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))) + +def save_version(setup_dir, module, v): + with open(os.path.join(setup_dir, module, "_version.py"), 'w') as fp: + return fp.write("__version__ = '%s'\n" % v) + +def read_version(setup_dir, module): + with open(os.path.join(setup_dir, module, "_version.py"), 'r') as fp: + return re.match("__version__ = '(.*)'$", fp.read()).groups()[0] + +def get_version(setup_dir, module): + env_version = os.environ.get("ARVADOS_BUILDING_VERSION") + + if env_version: + save_version(setup_dir, module, env_version) + else: + try: + save_version(setup_dir, module, git_latest_tag() + git_timestamp_tag()) + except subprocess.CalledProcessError: + pass + + return read_version(setup_dir, module)