Repository: pypa/setuptools_scm

Issue:
AttributeError: 'NoneType' object has no attribute 'groups' if tag has the wrong syntax
_(I  created this issue over in the setuptools repo (see https://github.com/pypa/setuptools/issues/2326 ) but I realize that it should actually be here, sorry)_

I happened to have a git tag of the wrong syntax, namely 2.0.0-alpha.5-PMC, leading to the above error. It was very difficult to track down for a lowly end-user of a package (atropos) that uses it, and which I forked in order to fix a few things. I did not know that tags were needed, let alone be of a very specific shape (and 2.0.0-alpha.5-PMC is not that extreme, right?) .

I have appended the stdout and stderr before git tag --delete 2.0.0-alpha.5-PMC (std*-bad.txt) and after deleting the offending tag (std*-good.txt) (done with export SETUPTOOLS_SCM_DEBUG=verbose)

[stdout-bad.txt](https://github.com/pypa/setuptools_scm/files/5067940/stdout-bad.txt)
[stderr-bad.txt](https://github.com/pypa/setuptools_scm/files/5067941/stderr-bad.txt)

[stdout-good.txt](https://github.com/pypa/setuptools_scm/files/5067944/stdout-good.txt)
[stderr-good.txt](https://github.com/pypa/setuptools_scm/files/5067945/stderr-good.txt)

I tried various older versions of setuptools-scm (back to 2.0.0 I recall correctly), all had the same or similar problem. I see several reports of people having similar trouble so it appears to be a general problem and one that occurs more often. I would love if this were more robust, i.e. I'd much rather have a version string 'unknown' or somesuch than a package that refuses to install ...

Cheers,
P

Discussion:

Patch:
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):


Test patch:
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")