Skip to content

Commit 0d9175a

Browse files
fix: version back compat
1 parent 60a4be9 commit 0d9175a

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def lint(session: nox.Session) -> None:
8181

8282
session.run("pre-commit", "run", "--all-files", *session.posargs)
8383

84+
8485
@nox.session()
8586
def slotscheck(session: nox.Session) -> None:
8687
"""Run slotscheck."""

pyproject.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: MIT
22

33
[build-system]
4-
requires = ["hatchling", "versioningit>=3.3.0"]
4+
requires = ["hatchling", "versioningit>=3.3.0,<4.0", "packaging"]
55
build-backend = "hatchling.build"
66

77
[project]
@@ -133,6 +133,11 @@ include = [
133133
]
134134
artifacts = ["disnake/_version.py"]
135135

136+
[tool.hatch.build.targets.sdist]
137+
include = [
138+
"scripts/versioning.py"
139+
]
140+
136141
[tool.hatch.version]
137142
source = "versioningit"
138143

@@ -148,9 +153,8 @@ distance = "{base_version}+{distance}.{vcs}{rev}"
148153
dirty = "{base_version}+d{build_date:%Y%m%d}"
149154
distance-dirty = "{base_version}.a{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"
150155

151-
[tool.versioningit.template-fields.version-tuple]
152-
split-on = '^(\d+)\.(\d+)\.(\d+)\.([a-zA-Z])(\d+)(?:.\d+)?'
153-
156+
[tool.versioningit.template-fields]
157+
method = { module = "scripts.versioning", value = "template_fields"}
154158

155159
[tool.versioningit.write]
156160
file = "disnake/_version.py"
@@ -169,11 +173,7 @@ class VersionInfo(NamedTuple):
169173
releaselevel: Literal["alpha", "beta", "candidate", "final"]
170174
serial: int
171175
172-
173-
# fmt: off
174-
version_info: VersionInfo = VersionInfo(*{version_tuple}[:5])
175-
# fmt: on
176-
176+
version_info: VersionInfo = VersionInfo{version_tuple}
177177
"""
178178

179179
[tool.ruff]
@@ -437,4 +437,3 @@ exclude_lines = [
437437
"^\\s*raise NotImplementedError$",
438438
"^\\s*\\.\\.\\.$",
439439
]
440-

scripts/versioning.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
import copy
4+
from typing import Any, Optional
5+
6+
import packaging.version
7+
from versioningit import VCSDescription
8+
9+
10+
def template_fields(
11+
*,
12+
version: str,
13+
description: Optional[VCSDescription],
14+
base_version: Optional[str],
15+
next_version: Optional[str],
16+
params: dict[str, Any],
17+
) -> dict[str, Any]:
18+
"""Implements the ``"basic"`` ``template-fields`` method"""
19+
params = copy.deepcopy(params)
20+
parsed_version = packaging.version.parse(version)
21+
fields: dict[str, Any] = {}
22+
if description is not None:
23+
fields.update(description.fields)
24+
fields["branch"] = description.branch
25+
if base_version is not None:
26+
fields["base_version"] = base_version
27+
if next_version is not None:
28+
fields["next_version"] = next_version
29+
fields["version"] = version
30+
31+
releaselevels = {
32+
"a": "alpha",
33+
"b": "beta",
34+
"rc": "candidate",
35+
"": "final",
36+
}
37+
38+
if parsed_version.pre:
39+
releaselevel = releaselevels.get(parsed_version.pre[0], "final")
40+
else:
41+
releaselevel = "final"
42+
43+
fields["version_tuple"] = (
44+
parsed_version.major,
45+
parsed_version.minor,
46+
parsed_version.micro,
47+
releaselevel,
48+
parsed_version.dev or 0,
49+
)
50+
try:
51+
fields["normalized_version"] = str(packaging.version.Version(version))
52+
except ValueError:
53+
fields["normalized_version"] = version
54+
return fields

0 commit comments

Comments
 (0)