Repository: pypa/setuptools_scm

Issue:
calver detection fails on -v prefixes when using non-normalized versions
`.../setuptools_scm/version.py:396: UserWarning: <ScmVersion v23.08.08.0 dist=2 node=... dirty=True branch=use-node-date-version-for-calver> does not correspond to a valid versioning date, assuming legacy version`

happens when trying to use non-normalized versions for calver

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 06a9c27..cb05707 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -43,6 +43,7 @@ bugfixes
 --------
 
 * fix #883: use HeadersParser to ensure only mime metadata in headers is used
+* fix #884: parse calver dates from versions with the v prefix
 
 v7.1.0
 ======
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index 05abd50..3a5dba0 100644
--- a/src/setuptools_scm/version.py
+++ b/src/setuptools_scm/version.py
@@ -307,7 +307,13 @@ def no_guess_dev_version(version: ScmVersion) -> str:
 
 
 _DATE_REGEX = re.compile(
-    r"^(?P<date>(?P<year>\d{2}|\d{4})(?:\.\d{1,2}){2})(?:\.(?P<patch>\d*))?$"
+    r"""
+    ^(?P<date>
+        (?P<prefix>[vV]?)
+        (?P<year>\d{2}|\d{4})(?:\.\d{1,2}){2})
+        (?:\.(?P<patch>\d*))?$
+    """,
+    re.VERBOSE,
 )
 
 
@@ -339,6 +345,10 @@ def guess_next_date_ver(
         # deduct date format if not provided
         if date_fmt is None:
             date_fmt = "%Y.%m.%d" if len(match.group("year")) == 4 else "%y.%m.%d"
+        if prefix := match.group("prefix"):
+            if not date_fmt.startswith(prefix):
+                date_fmt = prefix + date_fmt
+
     today = version.time.date()
     head_date = node_date or today
     # compute patch


Test patch:
diff --git a/testing/test_version.py b/testing/test_version.py
index b3bee8d..2485417 100644
--- a/testing/test_version.py
+++ b/testing/test_version.py
@@ -10,6 +10,7 @@ from setuptools_scm import Configuration
 from setuptools_scm import NonNormalizedVersion
 from setuptools_scm.version import calver_by_date
 from setuptools_scm.version import format_version
+from setuptools_scm.version import guess_next_date_ver
 from setuptools_scm.version import guess_next_version
 from setuptools_scm.version import meta
 from setuptools_scm.version import no_guess_dev_version
@@ -358,6 +359,29 @@ def test_calver_by_date_future_warning() -> None:
         )
 
 
+@pytest.mark.parametrize(
+    ["tag", "node_date", "expected"],
+    [
+        pytest.param("20.03.03", date(2020, 3, 4), "20.03.04.0", id="next day"),
+        pytest.param("20.03.03", date(2020, 3, 3), "20.03.03.1", id="same day"),
+        pytest.param(
+            "20.03.03.2", date(2020, 3, 3), "20.03.03.3", id="same day with patch"
+        ),
+        pytest.param(
+            "v20.03.03", date(2020, 3, 4), "v20.03.04.0", id="next day with v prefix"
+        ),
+    ],
+)
+def test_calver_guess_next_data(tag: str, node_date: date, expected: str) -> None:
+    version = meta(tag, config=c_non_normalize, node_date=node_date)
+    next = guess_next_date_ver(
+        version,
+        node_date=node_date,
+        version_cls=c_non_normalize.version_cls,
+    )
+    assert next == expected
+
+
 def test_custom_version_cls() -> None:
     """Test that we can pass our own version class instead of pkg_resources"""