From 7278de803df2021ddc185dda0cef1d565ab677ff Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 4 Apr 2018 16:57:27 -0400 Subject: [PATCH] 13200: Consolidate package version behavior in arvados_version Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- sdk/cwl/MANIFEST.in | 1 + sdk/cwl/arvados_version.py | 46 +++++++++++++++++++++++++---------- sdk/cwl/setup.py | 25 +++---------------- sdk/python/MANIFEST.in | 1 + sdk/python/arvados_version.py | 46 +++++++++++++++++++++++++---------- sdk/python/setup.py | 24 +++--------------- 6 files changed, 74 insertions(+), 69 deletions(-) diff --git a/sdk/cwl/MANIFEST.in b/sdk/cwl/MANIFEST.in index d1388b3ed4..50a29234be 100644 --- a/sdk/cwl/MANIFEST.in +++ b/sdk/cwl/MANIFEST.in @@ -4,3 +4,4 @@ include LICENSE-2.0.txt include README.rst +include arvados_version.py \ No newline at end of file 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) diff --git a/sdk/cwl/setup.py b/sdk/cwl/setup.py index d67b5ed47d..aed96c6023 100644 --- a/sdk/cwl/setup.py +++ b/sdk/cwl/setup.py @@ -3,36 +3,17 @@ # # SPDX-License-Identifier: Apache-2.0 +from __future__ import absolute_import import os import sys -import re from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(__file__) or '.' README = os.path.join(SETUP_DIR, 'README.rst') -env_version = os.environ.get("ARVADOS_BUILDING_VERSION") - -def save_version(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(module): - with open(os.path.join(SETUP_DIR, module, "_version.py"), 'r') as fp: - return re.match("__version__ = '(.*)'$", fp.read()).groups()[0] - -if env_version: - save_version("arvados_cwl", env_version) -else: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - save_version("arvados_cwl", vtag.git_latest_tag() + vtag.git_timestamp_tag()) - except ImportError: - pass - -version = read_version("arvados_cwl") +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados_cwl") setup(name='arvados-cwl-runner', version=version, diff --git a/sdk/python/MANIFEST.in b/sdk/python/MANIFEST.in index d1388b3ed4..50a29234be 100644 --- a/sdk/python/MANIFEST.in +++ b/sdk/python/MANIFEST.in @@ -4,3 +4,4 @@ include LICENSE-2.0.txt include README.rst +include arvados_version.py \ No newline at end of file diff --git a/sdk/python/arvados_version.py b/sdk/python/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/sdk/python/arvados_version.py +++ b/sdk/python/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) diff --git a/sdk/python/setup.py b/sdk/python/setup.py index a19b876fd3..4f487af0a9 100644 --- a/sdk/python/setup.py +++ b/sdk/python/setup.py @@ -3,6 +3,7 @@ # # SPDX-License-Identifier: Apache-2.0 +from __future__ import absolute_import import os import sys import re @@ -12,27 +13,8 @@ from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(__file__) or '.' README = os.path.join(SETUP_DIR, 'README.rst') -env_version = os.environ.get("ARVADOS_BUILDING_VERSION") - -def save_version(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(module): - with open(os.path.join(SETUP_DIR, module, "_version.py"), 'r') as fp: - return re.match("__version__ = '(.*)'$", fp.read()).groups()[0] - -if env_version: - save_version("arvados", env_version) -else: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - save_version("arvados", vtag.git_latest_tag() + vtag.git_timestamp_tag()) - except ImportError: - pass - -version = read_version("arvados") +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") short_tests_only = False if '--short-tests-only' in sys.argv: -- 2.30.2