Skip to content

Commit

Permalink
Change: Support full year (YYYY) for calendar versioning (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself authored Aug 22, 2023
1 parent f448aba commit 5252b56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pontos/version/_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,37 @@ def next_calendar_version(cls, current_version: Version) -> Version:
today = datetime.today()
current_year_short = today.year % 100

if current_version.major < current_year_short or (
current_version.major == current_year_short
if current_version.major > 2000:
# version expected to be YYYY.MM.P
current_year = today.year
else:
# version expected to be YY.MM.P
current_year = current_year_short

if current_version.major < current_year or (
current_version.major == current_year
and current_version.minor < today.month
):
return cls.version_from_string(
f"{current_year_short}.{today.month}.0"
)
return cls.version_from_string(f"{current_year}.{today.month}.0")

if (
current_version.major == today.year % 100
current_version.major == current_year
and current_version.minor == today.month
):
if current_version.dev is None:
release_version = cls.version_from_string(
f"{current_year_short}.{today.month}."
f"{current_year}.{today.month}."
f"{current_version.patch + 1}"
)
else:
release_version = cls.version_from_string(
f"{current_year_short}.{today.month}."
f"{current_version.patch}"
f"{current_year}.{today.month}." f"{current_version.patch}"
)
return release_version
else:
raise VersionError(
f"'{current_version}' is higher than "
f"'{current_year_short}.{today.month}'."
f"'{current_year}.{today.month}'."
)

@classmethod
Expand Down
13 changes: 13 additions & 0 deletions tests/version/schemes/test_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,20 @@ def test_next_calendar_versions(self):
f"19.{today.month}.1.dev3",
f"{year_short}.{today.month}.1.dev3",
f"{year_short}.{today.month}.1",
"2022.4.1",
"2023.5.1",
f"{today.year}.{today.month}.1.dev2",
f"{today.year}.{today.month}.1",
]
assert_versions = [
f"{year_short}.{today.month}.0",
f"{year_short}.{today.month}.0",
f"{year_short}.{today.month}.1",
f"{year_short}.{today.month}.2",
f"{today.year}.{today.month}.0",
f"{today.year}.{today.month}.0",
f"{today.year}.{today.month}.1",
f"{today.year}.{today.month}.2",
]

for current_version, assert_version in zip(
Expand Down Expand Up @@ -571,6 +579,11 @@ def test_next_calendar_version_error(self):
Version.from_string(f"{year_short}.{today.month + 1}.0")
)

with self.assertRaisesRegex(VersionError, "'.+' is higher than '.+'."):
calculator.next_calendar_version(
Version.from_string(f"{today.year + 1}.{today.month + 1}.0")
)

def test_next_minor_version(self):
calculator = VersionCalculator()

Expand Down

0 comments on commit 5252b56

Please sign in to comment.