From 72db9a32efbe3ca8da6e592d139f3fed675fa079 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 31 Mar 2022 15:32:14 -0400 Subject: [PATCH] Modernized versioning Using setuptools_scm; we can automatically generate version numbers instead of using this odd combination of hardcoding and running git commands. This method is faster as well. Signed-off-by: Zack Cerza --- pyproject.toml | 9 ++++++++- setup.cfg | 1 - teuthology/__init__.py | 25 ++++++------------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b0f076532a..ece6fe5f51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,10 @@ [build-system] -requires = ["setuptools>=42"] build-backend = "setuptools.build_meta" +requires = [ + "setuptools>=45", + "wheel", + "setuptools_scm>=6.2", +] + +[tool.setuptools_scm] +version_scheme = "python-simplified-semver" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 0de92b8a1e..4bfdfab5dc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] name = teuthology -version = attr: teuthology.__version__ long_description = file: README.rst long_description_content_type = text/x-rst url = https://github.com/ceph/teuthology diff --git a/teuthology/__init__.py b/teuthology/__init__.py index 2ef5aeb144..4781f59bc1 100644 --- a/teuthology/__init__.py +++ b/teuthology/__init__.py @@ -1,5 +1,11 @@ from __future__ import print_function import os +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata + +__version__ = importlib_metadata.version("teuthology") # Tell gevent not to patch os.waitpid() since it is susceptible to race # conditions. See: @@ -33,25 +39,6 @@ from teuthology.orchestra import monkey monkey.patch_all() import logging -import subprocess - -__version__ = '1.1.0' - -# do our best, but if it fails, continue with above - -try: - teuthology_dir = os.path.dirname(os.path.realpath(__file__)) - site_dir = os.path.dirname(teuthology_dir) - git_dir = os.path.join(site_dir, '.git') - # make sure we use git repo otherwise it is a released version - if os.path.exists(git_dir): - __version__ += '-' + str(subprocess.check_output( - 'git rev-parse --short HEAD'.split(), - cwd=site_dir - ).decode()).strip() -except Exception as e: - # before logging; should be unusual - print("Can't get version from git rev-parse %s" % e, file=sys.stderr) # If we are running inside a virtualenv, ensure we have its 'bin' directory in # our PATH. This doesn't happen automatically if scripts are called without -- 2.39.5