Skip to content

Commit ada960d

Browse files
fix #884: handle v prefixes for calver by date
1 parent 357f6e0 commit ada960d

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bugfixes
4343
--------
4444

4545
* fix #883: use HeadersParser to ensure only mime metadata in headers is used
46+
* fix #884: parse calver dates from versions with the v prefix
4647

4748
v7.1.0
4849
======

src/setuptools_scm/version.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,13 @@ def no_guess_dev_version(version: ScmVersion) -> str:
307307

308308

309309
_DATE_REGEX = re.compile(
310-
r"^(?P<date>(?P<year>\d{2}|\d{4})(?:\.\d{1,2}){2})(?:\.(?P<patch>\d*))?$"
310+
r"""
311+
^(?P<date>
312+
(?P<prefix>[vV]?)
313+
(?P<year>\d{2}|\d{4})(?:\.\d{1,2}){2})
314+
(?:\.(?P<patch>\d*))?$
315+
""",
316+
re.VERBOSE,
311317
)
312318

313319

@@ -339,6 +345,10 @@ def guess_next_date_ver(
339345
# deduct date format if not provided
340346
if date_fmt is None:
341347
date_fmt = "%Y.%m.%d" if len(match.group("year")) == 4 else "%y.%m.%d"
348+
if prefix := match.group("prefix"):
349+
if not date_fmt.startswith(prefix):
350+
date_fmt = prefix + date_fmt
351+
342352
today = version.time.date()
343353
head_date = node_date or today
344354
# compute patch

testing/test_version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from setuptools_scm import NonNormalizedVersion
1111
from setuptools_scm.version import calver_by_date
1212
from setuptools_scm.version import format_version
13+
from setuptools_scm.version import guess_next_date_ver
1314
from setuptools_scm.version import guess_next_version
1415
from setuptools_scm.version import meta
1516
from setuptools_scm.version import no_guess_dev_version
@@ -358,6 +359,29 @@ def test_calver_by_date_future_warning() -> None:
358359
)
359360

360361

362+
@pytest.mark.parametrize(
363+
["tag", "node_date", "expected"],
364+
[
365+
pytest.param("20.03.03", date(2020, 3, 4), "20.03.04.0", id="next day"),
366+
pytest.param("20.03.03", date(2020, 3, 3), "20.03.03.1", id="same day"),
367+
pytest.param(
368+
"20.03.03.2", date(2020, 3, 3), "20.03.03.3", id="same day with patch"
369+
),
370+
pytest.param(
371+
"v20.03.03", date(2020, 3, 4), "v20.03.04.0", id="next day with v prefix"
372+
),
373+
],
374+
)
375+
def test_calver_guess_next_data(tag: str, node_date: date, expected: str) -> None:
376+
version = meta(tag, config=c_non_normalize, node_date=node_date)
377+
next = guess_next_date_ver(
378+
version,
379+
node_date=node_date,
380+
version_cls=c_non_normalize.version_cls,
381+
)
382+
assert next == expected
383+
384+
361385
def test_custom_version_cls() -> None:
362386
"""Test that we can pass our own version class instead of pkg_resources"""
363387

0 commit comments

Comments
 (0)