Skip to content
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
18 changes: 12 additions & 6 deletions src/setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,27 @@ def guess_next_date_ver(version, node_date=None, date_fmt=None, version_cls=None
"""
match = date_ver_match(version)
if match is None:
raise ValueError(
"{version} does not correspond to a valid versioning date, "
"please correct or use a custom version scheme".format(version=version)
warnings.warn(
f"{version} does not correspond to a valid versioning date, "
"assuming legacy version"
)
if date_fmt is None:
date_fmt = "%y.%m.%d"

# 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"
head_date = node_date or datetime.date.today()
# compute patch
tag_date = datetime.datetime.strptime(match.group("date"), date_fmt).date()
if match is None:
tag_date = datetime.date.today()
else:
tag_date = datetime.datetime.strptime(match.group("date"), date_fmt).date()
if tag_date == head_date:
patch = match.group("patch") or "0"
patch = "0" if match is None else (match.group("patch") or "0")
patch = int(patch) + 1
else:
if tag_date > head_date:
if tag_date > head_date and match is not None:
# warn on future times
warnings.warn(
"your previous tag ({}) is ahead your node date ({})".format(
Expand Down
15 changes: 14 additions & 1 deletion testing/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def date_to_str(date_=None, days_offset=0, fmt="{dt:%y}.{dt.month}.{dt.day}"):
meta(date_to_str() + ".1", config=c), date_to_str() + ".1", id="exact patch"
),
pytest.param(
meta(date_to_str(fmt="20.01.02"), config=c),
meta("20.01.02", config=c),
"20.1.2",
id="leading 0s",
),
Expand Down Expand Up @@ -256,6 +256,19 @@ def date_to_str(date_=None, days_offset=0, fmt="{dt:%y}.{dt.month}.{dt.day}"):
date_to_str(date.today() - timedelta(days=2)) + ".3.dev2",
id="node date distance",
),
pytest.param(
meta(
"1.2.0",
config=c,
distance=2,
node_date=date.today() - timedelta(days=2),
),
date_to_str(days_offset=2) + ".0.dev2",
marks=pytest.mark.filterwarnings(
"ignore:.*not correspond to a valid versioning date.*:UserWarning"
),
id="using on old version tag",
),
],
)
def test_calver_by_date(version, expected_next):
Expand Down