diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 06a9c276..cb057075 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 05abd50c..3a5dba05 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(?P\d{2}|\d{4})(?:\.\d{1,2}){2})(?:\.(?P\d*))?$" + r""" + ^(?P + (?P[vV]?) + (?P\d{2}|\d{4})(?:\.\d{1,2}){2}) + (?:\.(?P\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 diff --git a/testing/test_version.py b/testing/test_version.py index b3bee8d3..24854177 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -10,6 +10,7 @@ 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"""