Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #884: handle v prefixes for calver by date #897

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
======
Expand Down
12 changes: 11 additions & 1 deletion src/setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions testing/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""

Expand Down
Loading