From ef36e47111a8ed9d9693107e6a9d5db87592a794 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 29 Nov 2020 21:51:52 +0100 Subject: fix #471: better error when a simplicistic version bump fails --- CHANGELOG.rst | 2 +- src/setuptools_scm/version.py | 11 +++++++++-- testing/test_version.py | 20 +++++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0d7a1c3..c376a55 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ v4.2.0 ====== - +* fix #471: better error for version bump failing on complex but accepted tag * fix #479: raise indicative error when tags carry non-parsable information * Add `no-guess-dev` which does no next version guessing, just adds `.post1.devN` in case there are new commits after the tag diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index c58be7e..40eadc8 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -235,8 +235,15 @@ def _bump_dev(version): def _bump_regex(version): - prefix, tail = re.match(r"(.*?)(\d+)$", version).groups() - return "%s%d" % (prefix, int(tail) + 1) + match = re.match(r"(.*?)(\d+)$", version) + if match is None: + raise ValueError( + "{version} does not end with a number to bump, " + "please correct or use a custom version scheme".format(version=version) + ) + else: + prefix, tail = match.groups() + return "%s%d" % (prefix, int(tail) + 1) def guess_next_dev_version(version): diff --git a/testing/test_version.py b/testing/test_version.py index 38c98bf..722b8e8 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -6,6 +6,7 @@ from setuptools_scm.version import ( release_branch_semver_version, tags_to_versions, no_guess_dev_version, + guess_next_version, ) @@ -128,19 +129,28 @@ def test_no_guess_version(version, expected_next): ], ) def test_tag_regex1(tag, expected): - config = Configuration() if "+" in tag: # pytest bug wrt cardinality with pytest.warns(UserWarning): - result = meta(tag, config=config) + result = meta(tag, config=c) else: - result = meta(tag, config=config) + result = meta(tag, config=c) assert result.tag.public == expected @pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/286") def test_tags_to_versions(): - config = Configuration() - versions = tags_to_versions(["1.0", "2.0", "3.0"], config=config) + versions = tags_to_versions(["1.0", "2.0", "3.0"], config=c) assert isinstance(versions, list) # enable subscription + + +@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/471") +def test_version_bump_bad(): + with pytest.raises( + ValueError, + match=".*does not end with a number to bump, " + "please correct or use a custom version scheme", + ): + + guess_next_version(tag_version="2.0.0-alpha.5-PMC") -- cgit v1.2.1