From c334c1a486114024ed22bfb88a1aa79dc1d99772 Mon Sep 17 00:00:00 2001 From: Fernando Monserrat Date: Wed, 4 Apr 2018 18:42:08 -0300 Subject: [PATCH] 13200: Consolidate package version behavior in arvados_version for all the python packages Arvados-DCO-1.1-Signed-off-by: Fernando Monserrat --- sdk/pam/MANIFEST.in | 1 + sdk/pam/arvados_version.py | 40 ++++++++++++++++++ sdk/pam/setup.py | 22 +++++----- services/dockercleaner/MANIFEST.in | 1 + services/dockercleaner/arvados_version.py | 46 +++++++++++++++------ services/dockercleaner/setup.py | 25 +++++------ services/fuse/MANIFEST.in | 1 + services/fuse/arvados_version.py | 46 +++++++++++++++------ services/fuse/setup.py | 19 +++------ services/nodemanager/MANIFEST.in | 1 + services/nodemanager/arvados_version.py | 46 +++++++++++++++------ services/nodemanager/setup.py | 23 +++++------ tools/crunchstat-summary/MANIFEST.in | 1 + tools/crunchstat-summary/arvados_version.py | 46 +++++++++++++++------ tools/crunchstat-summary/setup.py | 22 +++++----- 15 files changed, 226 insertions(+), 114 deletions(-) create mode 100644 sdk/pam/arvados_version.py diff --git a/sdk/pam/MANIFEST.in b/sdk/pam/MANIFEST.in index 553d1a528c..48892fa728 100644 --- a/sdk/pam/MANIFEST.in +++ b/sdk/pam/MANIFEST.in @@ -7,3 +7,4 @@ include README.rst include examples/shellinabox include lib/libpam_arvados.py include pam-configs/arvados +include arvados_version.py \ No newline at end of file diff --git a/sdk/pam/arvados_version.py b/sdk/pam/arvados_version.py new file mode 100644 index 0000000000..a24d53dad6 --- /dev/null +++ b/sdk/pam/arvados_version.py @@ -0,0 +1,40 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + +import subprocess +import time +import os +import re + +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/pam/setup.py b/sdk/pam/setup.py index 35ed08238d..23f23310ca 100755 --- a/sdk/pam/setup.py +++ b/sdk/pam/setup.py @@ -3,10 +3,11 @@ # # SPDX-License-Identifier: Apache-2.0 +from __future__ import absolute_import import glob import os import sys -import setuptools.command.egg_info as egg_info_cmd +import re import subprocess from setuptools import setup, find_packages @@ -14,15 +15,13 @@ from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(__file__) or '.' README = os.path.join(SETUP_DIR, 'README.rst') -tagger = egg_info_cmd.egg_info -version = os.environ.get("ARVADOS_BUILDING_VERSION") -if not version: - version = "0.1" - try: - import gittaggers - tagger = gittaggers.EggInfoFromGit - except ImportError: - pass +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") + +short_tests_only = False +if '--short-tests-only' in sys.argv: + short_tests_only = True + sys.argv.remove('--short-tests-only') setup(name='arvados-pam', version=version, @@ -56,6 +55,5 @@ setup(name='arvados-pam', ], test_suite='tests', tests_require=['pbr<1.7.0', 'mock>=1.0', 'python-pam'], - zip_safe=False, - cmdclass={'egg_info': tagger}, + zip_safe=False ) diff --git a/services/dockercleaner/MANIFEST.in b/services/dockercleaner/MANIFEST.in index 2a14fab659..5d510b41a3 100644 --- a/services/dockercleaner/MANIFEST.in +++ b/services/dockercleaner/MANIFEST.in @@ -4,3 +4,4 @@ include agpl-3.0.txt include arvados-docker-cleaner.service +include arvados_version.py \ No newline at end of file diff --git a/services/dockercleaner/arvados_version.py b/services/dockercleaner/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/services/dockercleaner/arvados_version.py +++ b/services/dockercleaner/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/services/dockercleaner/setup.py b/services/dockercleaner/setup.py index b287bd00d2..ebc88b7e36 100644 --- a/services/dockercleaner/setup.py +++ b/services/dockercleaner/setup.py @@ -3,21 +3,23 @@ # # SPDX-License-Identifier: AGPL-3.0 +from __future__ import absolute_import import os import sys -import setuptools.command.egg_info as egg_info_cmd +import re from setuptools import setup, find_packages -tagger = egg_info_cmd.egg_info -version = os.environ.get("ARVADOS_BUILDING_VERSION") -if not version: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - version = vtag.git_latest_tag() + vtag.git_timestamp_tag() - except ImportError: - pass +SETUP_DIR = os.path.dirname(__file__) or '.' +README = os.path.join(SETUP_DIR, 'README.rst') + +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") + +short_tests_only = False +if '--short-tests-only' in sys.argv: + short_tests_only = True + sys.argv.remove('--short-tests-only') setup(name="arvados-docker-cleaner", version=version, @@ -43,6 +45,5 @@ setup(name="arvados-docker-cleaner", 'mock', ], test_suite='tests', - zip_safe=False, - cmdclass={'egg_info': tagger}, + zip_safe=False ) diff --git a/services/fuse/MANIFEST.in b/services/fuse/MANIFEST.in index 5692a6886b..7322a0ab52 100644 --- a/services/fuse/MANIFEST.in +++ b/services/fuse/MANIFEST.in @@ -4,3 +4,4 @@ include agpl-3.0.txt include README.rst +include arvados_version.py \ No newline at end of file diff --git a/services/fuse/arvados_version.py b/services/fuse/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/services/fuse/arvados_version.py +++ b/services/fuse/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/services/fuse/setup.py b/services/fuse/setup.py index 8bc11315fa..d3c5033fcc 100644 --- a/services/fuse/setup.py +++ b/services/fuse/setup.py @@ -3,25 +3,19 @@ # # SPDX-License-Identifier: AGPL-3.0 +from __future__ import absolute_import import os import sys -import setuptools.command.egg_info as egg_info_cmd +import re from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(__file__) or '.' README = os.path.join(SETUP_DIR, 'README.rst') -tagger = egg_info_cmd.egg_info -version = os.environ.get("ARVADOS_BUILDING_VERSION") -if not version: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - version = vtag.git_latest_tag() + vtag.git_timestamp_tag() - except ImportError: - pass - +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") + short_tests_only = False if '--short-tests-only' in sys.argv: short_tests_only = True @@ -52,6 +46,5 @@ setup(name='arvados_fuse', ], test_suite='tests', tests_require=['pbr<1.7.0', 'mock>=1.0', 'PyYAML'], - zip_safe=False, - cmdclass={'egg_info': tagger}, + zip_safe=False ) diff --git a/services/nodemanager/MANIFEST.in b/services/nodemanager/MANIFEST.in index 5692a6886b..7322a0ab52 100644 --- a/services/nodemanager/MANIFEST.in +++ b/services/nodemanager/MANIFEST.in @@ -4,3 +4,4 @@ include agpl-3.0.txt include README.rst +include arvados_version.py \ No newline at end of file diff --git a/services/nodemanager/arvados_version.py b/services/nodemanager/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/services/nodemanager/arvados_version.py +++ b/services/nodemanager/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/services/nodemanager/setup.py b/services/nodemanager/setup.py index 9ae1135b88..b472c8833b 100644 --- a/services/nodemanager/setup.py +++ b/services/nodemanager/setup.py @@ -3,25 +3,23 @@ # # SPDX-License-Identifier: AGPL-3.0 +from __future__ import absolute_import import os import sys -import setuptools.command.egg_info as egg_info_cmd +import re from setuptools import setup, find_packages -SETUP_DIR = os.path.dirname(__file__) or "." +SETUP_DIR = os.path.dirname(__file__) or '.' README = os.path.join(SETUP_DIR, 'README.rst') -tagger = egg_info_cmd.egg_info -version = os.environ.get("ARVADOS_BUILDING_VERSION") -if not version: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - version = vtag.git_latest_tag() + vtag.git_timestamp_tag() - except ImportError: - pass +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") +short_tests_only = False +if '--short-tests-only' in sys.argv: + short_tests_only = True + sys.argv.remove('--short-tests-only') setup(name='arvados-node-manager', version=version, @@ -51,6 +49,5 @@ setup(name='arvados-node-manager', 'mock>=1.0', 'apache-libcloud>=2.3', ], - zip_safe=False, - cmdclass={'egg_info': tagger}, + zip_safe=False ) diff --git a/tools/crunchstat-summary/MANIFEST.in b/tools/crunchstat-summary/MANIFEST.in index d1c3037ca2..764a4735ef 100644 --- a/tools/crunchstat-summary/MANIFEST.in +++ b/tools/crunchstat-summary/MANIFEST.in @@ -5,3 +5,4 @@ include agpl-3.0.txt include crunchstat_summary/dygraphs.js include crunchstat_summary/synchronizer.js +include arvados_version.py \ No newline at end of file diff --git a/tools/crunchstat-summary/arvados_version.py b/tools/crunchstat-summary/arvados_version.py index db46417ea6..a24d53dad6 100644 --- a/tools/crunchstat-summary/arvados_version.py +++ b/tools/crunchstat-summary/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/tools/crunchstat-summary/setup.py b/tools/crunchstat-summary/setup.py index 0965faea83..6cd22b1b9f 100755 --- a/tools/crunchstat-summary/setup.py +++ b/tools/crunchstat-summary/setup.py @@ -3,24 +3,23 @@ # # SPDX-License-Identifier: AGPL-3.0 +from __future__ import absolute_import import os import sys -import setuptools.command.egg_info as egg_info_cmd +import re from setuptools import setup, find_packages SETUP_DIR = os.path.dirname(__file__) or '.' +README = os.path.join(SETUP_DIR, 'README.rst') -tagger = egg_info_cmd.egg_info -version = os.environ.get("ARVADOS_BUILDING_VERSION") -if not version: - try: - import arvados_version - vtag = arvados_version.VersionInfoFromGit() - version = vtag.git_latest_tag() + vtag.git_timestamp_tag() - except ImportError: - pass +import arvados_version +version = arvados_version.get_version(SETUP_DIR, "arvados") +short_tests_only = False +if '--short-tests-only' in sys.argv: + short_tests_only = True + sys.argv.remove('--short-tests-only') setup(name='crunchstat_summary', version=version, @@ -43,6 +42,5 @@ setup(name='crunchstat_summary', ], test_suite='tests', tests_require=['pbr<1.7.0', 'mock>=1.0'], - zip_safe=False, - cmdclass={'egg_info': tagger}, + zip_safe=False ) -- 2.30.2