From a23d5fe61d9dc421666d5f23334d454426ad311c Mon Sep 17 00:00:00 2001 From: Josh Cannon Date: Fri, 19 Jan 2024 11:05:01 -0600 Subject: [PATCH] Add a "only-version" version scheme (#1005) * Add "just-tag" * docs too * rename * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Dont autoformat this * docs warning --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/extending.md | 5 +++++ pyproject.toml | 1 + src/setuptools_scm/version.py | 4 ++++ testing/test_version.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/docs/extending.md b/docs/extending.md index 957c762e..fa71841e 100644 --- a/docs/extending.md +++ b/docs/extending.md @@ -84,6 +84,11 @@ representing the version. `no-guess-dev` : Does no next version guessing, just adds `.post1.devN` +`only-version` +: Only use the version from the tag, as given. + + !!! warning "This means version is no longer pseudo unique per commit" + ### `setuptools_scm.local_scheme` Configures how the local part of a version is rendered given a diff --git a/pyproject.toml b/pyproject.toml index a93544d2..0df1499c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,6 +98,7 @@ PKG-INFO = "setuptools_scm.fallbacks:parse_pkginfo" "calver-by-date" = "setuptools_scm.version:calver_by_date" "guess-next-dev" = "setuptools_scm.version:guess_next_dev_version" "no-guess-dev" = "setuptools_scm.version:no_guess_dev_version" +"only-version" = "setuptools_scm.version:only_version" "post-release" = "setuptools_scm.version:postrelease_version" "python-simplified-semver" = "setuptools_scm.version:simplified_semver_version" "release-branch-semver" = "setuptools_scm.version:release_branch_semver_version" diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index f43e14b6..8bf03057 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -299,6 +299,10 @@ def release_branch_semver(version: ScmVersion) -> str: return release_branch_semver_version(version) +def only_version(version: ScmVersion) -> str: + return version.format_with("{tag}") + + def no_guess_dev_version(version: ScmVersion) -> str: if version.exact: return version.format_with("{tag}") diff --git a/testing/test_version.py b/testing/test_version.py index ea4c7d99..5aace367 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -15,6 +15,7 @@ from setuptools_scm.version import guess_next_version from setuptools_scm.version import meta from setuptools_scm.version import no_guess_dev_version +from setuptools_scm.version import only_version from setuptools_scm.version import release_branch_semver_version from setuptools_scm.version import ScmVersion from setuptools_scm.version import simplified_semver_version @@ -170,6 +171,33 @@ def test_bump_dev_version_nonzero_raises() -> None: guess_next_version(m("1.0.dev1")) +@pytest.mark.parametrize( + "version", + [ + "1.dev0", + "1.0.dev456", + "1.0a1", + "1.0a2.dev456", + "1.0a12.dev456", + "1.0a12", + "1.0b1.dev456", + "1.0b2", + "1.0b2.post345.dev456", + "1.0b2.post345", + "1.0rc1.dev456", + "1.0rc1", + "1.0", + "1.0.post456.dev34", + "1.0.post456", + "1.0.15", + "1.1.dev1", + ], +) +def test_only_version(version: str) -> None: + assert version == only_version(meta(version, config=c)) + assert version == only_version(meta(version, distance=2, config=c)) + + @pytest.mark.parametrize( ("tag", "expected"), [