From 17dffb50c34036a54233a3d0441585342459bf8c Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sun, 5 Mar 2023 08:45:57 -0500 Subject: [PATCH] Allow __version__ to be overridden for release setuptools_scm always generates dev __version__; during release we might need to use the exact pinned version. --- pyproject.toml | 3 --- setup.py | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 96bad45..b5b50cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,3 @@ [build-system] requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"] - -[tool.setuptools_scm] -write_to = "gpustat/_version.py" diff --git a/setup.py b/setup.py index 1911641..f3f3e33 100644 --- a/setup.py +++ b/setup.py @@ -22,10 +22,20 @@ def read_version(): "setuptools_scm needs to be installed manually. " "Or consider running `pip install -e .` instead." ) - return setuptools_scm.get_version() + version = setuptools_scm.get_version() + setuptools_scm.dump_version(root=__PATH__, version=version, + write_to='gpustat/_version.py') + return version -__version__ = read_version() +if os.getenv("GPUSTAT_VERSION"): + # release process, e.g. GPUSTAT_VERSION="1.1" python setup.py sdist + __version__ = os.environ["GPUSTAT_VERSION"] +else: + # Let dev version auto-generated from git tags, or + # grab the version information from PKG-INFO for source distribution + __version__ = read_version() + # brought from https://github.com/kennethreitz/setup.py @@ -62,7 +72,8 @@ def run(self): pass self.status('Building Source and Wheel (universal) distribution ...') - os.system('{0} setup.py sdist'.format(sys.executable)) + os.system("GPUSTAT_VERSION='{}' sh -c '{} setup.py sdist'".format( + __version__, sys.executable)) self.status('Uploading the package to PyPI via Twine ...') ret = os.system('twine upload dist/*')