X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a7cd9cfe43468acd6cbc1b674241fb3c7ffcf0cf..5764b83d10b4969ac99ec8c4d716670604b20e82:/sdk/cwl/arvados_version.py diff --git a/sdk/cwl/arvados_version.py b/sdk/cwl/arvados_version.py index 88cf1ed7ca..006194935a 100644 --- a/sdk/cwl/arvados_version.py +++ b/sdk/cwl/arvados_version.py @@ -7,39 +7,40 @@ import time import os import re -SETUP_DIR = os.path.dirname(__file__) or '.' - -def git_latest_tag(): - gitinfo = subprocess.check_output( - ['git', 'describe', '--abbrev=0']).strip() - return str(gitinfo.decode('utf-8')) +SETUP_DIR = os.path.dirname(os.path.abspath(__file__)) +VERSION_PATHS = { + SETUP_DIR, + os.path.abspath(os.path.join(SETUP_DIR, "../python")), + os.path.abspath(os.path.join(SETUP_DIR, "../../build/version-at-commit.sh")) + } def choose_version_from(): - sdk_ts = subprocess.check_output( - ['git', 'log', '--first-parent', '--max-count=1', - '--format=format:%ct', os.path.join(SETUP_DIR, "../python")]).strip() - cwl_ts = subprocess.check_output( - ['git', 'log', '--first-parent', '--max-count=1', - '--format=format:%ct', SETUP_DIR]).strip() - if int(sdk_ts) > int(cwl_ts): - getver = os.path.join(SETUP_DIR, "../python") - else: - getver = SETUP_DIR + ts = {} + for path in VERSION_PATHS: + ts[subprocess.check_output( + ['git', 'log', '--first-parent', '--max-count=1', + '--format=format:%ct', path]).strip()] = path + + sorted_ts = sorted(ts.items()) + getver = sorted_ts[-1][1] + print("Using "+getver+" for version number calculation of "+SETUP_DIR) return getver -def git_timestamp_tag(): - gitinfo = subprocess.check_output( - ['git', 'log', '--first-parent', '--max-count=1', - '--format=format:%ct', choose_version_from()]).strip() - return str(time.strftime('.%Y%m%d%H%M%S', time.gmtime(int(gitinfo)))) +def git_version_at_commit(): + curdir = choose_version_from() + myhash = subprocess.check_output(['git', 'log', '-n1', '--first-parent', + '--format=%H', curdir]).strip() + myversion = subprocess.check_output([SETUP_DIR+'/../../build/version-at-commit.sh', myhash]).strip().decode() + return myversion 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) + v = v.replace("~dev", ".dev").replace("~rc", "rc") + with open(os.path.join(setup_dir, module, "_version.py"), 'wt') 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] + with open(os.path.join(setup_dir, module, "_version.py"), 'rt') as fp: + return re.match("__version__ = '(.*)'$", fp.read()).groups()[0] def get_version(setup_dir, module): env_version = os.environ.get("ARVADOS_BUILDING_VERSION") @@ -48,8 +49,9 @@ def get_version(setup_dir, module): save_version(setup_dir, module, env_version) else: try: - save_version(setup_dir, module, git_latest_tag() + git_timestamp_tag()) - except (subprocess.CalledProcessError, OSError): + save_version(setup_dir, module, git_version_at_commit()) + except (subprocess.CalledProcessError, OSError) as err: + print("ERROR: {0}".format(err)) pass return read_version(setup_dir, module)