Skip to content

Commit 8df1840

Browse files
Merge pull request #603 from RonnyPfannschmidt/fix-593-calver-by-date-warn-on-legacy-version-style
fix #593: allow calver-by-date on top of legacy version
2 parents ff88ecd + 261a4f0 commit 8df1840

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/setuptools_scm/version.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,27 @@ def guess_next_date_ver(version, node_date=None, date_fmt=None, version_cls=None
323323
"""
324324
match = date_ver_match(version)
325325
if match is None:
326-
raise ValueError(
327-
"{version} does not correspond to a valid versioning date, "
328-
"please correct or use a custom version scheme".format(version=version)
326+
warnings.warn(
327+
f"{version} does not correspond to a valid versioning date, "
328+
"assuming legacy version"
329329
)
330+
if date_fmt is None:
331+
date_fmt = "%y.%m.%d"
332+
330333
# deduct date format if not provided
331334
if date_fmt is None:
332335
date_fmt = "%Y.%m.%d" if len(match.group("year")) == 4 else "%y.%m.%d"
333336
head_date = node_date or datetime.date.today()
334337
# compute patch
335-
tag_date = datetime.datetime.strptime(match.group("date"), date_fmt).date()
338+
if match is None:
339+
tag_date = datetime.date.today()
340+
else:
341+
tag_date = datetime.datetime.strptime(match.group("date"), date_fmt).date()
336342
if tag_date == head_date:
337-
patch = match.group("patch") or "0"
343+
patch = "0" if match is None else (match.group("patch") or "0")
338344
patch = int(patch) + 1
339345
else:
340-
if tag_date > head_date:
346+
if tag_date > head_date and match is not None:
341347
# warn on future times
342348
warnings.warn(
343349
"your previous tag ({}) is ahead your node date ({})".format(

testing/test_version.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def date_to_str(date_=None, days_offset=0, fmt="{dt:%y}.{dt.month}.{dt.day}"):
208208
meta(date_to_str() + ".1", config=c), date_to_str() + ".1", id="exact patch"
209209
),
210210
pytest.param(
211-
meta(date_to_str(fmt="20.01.02"), config=c),
211+
meta("20.01.02", config=c),
212212
"20.1.2",
213213
id="leading 0s",
214214
),
@@ -256,6 +256,19 @@ def date_to_str(date_=None, days_offset=0, fmt="{dt:%y}.{dt.month}.{dt.day}"):
256256
date_to_str(date.today() - timedelta(days=2)) + ".3.dev2",
257257
id="node date distance",
258258
),
259+
pytest.param(
260+
meta(
261+
"1.2.0",
262+
config=c,
263+
distance=2,
264+
node_date=date.today() - timedelta(days=2),
265+
),
266+
date_to_str(days_offset=2) + ".0.dev2",
267+
marks=pytest.mark.filterwarnings(
268+
"ignore:.*not correspond to a valid versioning date.*:UserWarning"
269+
),
270+
id="using on old version tag",
271+
),
259272
],
260273
)
261274
def test_calver_by_date(version, expected_next):

0 commit comments

Comments
 (0)