Skip to content

Commit 00ea9e3

Browse files
fix: version back compat
1 parent aa4bd66 commit 00ea9e3

File tree

3 files changed

+64
-30
lines changed

3 files changed

+64
-30
lines changed

noxfile.py

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

8989
session.run("pre-commit", "run", "--all-files", *session.posargs)
9090

91+
9192
@nox.session()
9293
def slotscheck(session: nox.Session) -> None:
9394
"""Run slotscheck."""

pyproject.toml

Lines changed: 9 additions & 30 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]
@@ -127,6 +127,11 @@ include = [
127127
]
128128
artifacts = ["disnake/_version.py"]
129129

130+
[tool.hatch.build.targets.sdist]
131+
include = [
132+
"scripts/versioning.py"
133+
]
134+
130135
[tool.hatch.version]
131136
source = "versioningit"
132137

@@ -142,9 +147,8 @@ distance = "{base_version}+{distance}.{vcs}{rev}"
142147
dirty = "{base_version}+d{build_date:%Y%m%d}"
143148
distance-dirty = "{base_version}.a{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"
144149

145-
[tool.versioningit.template-fields.version-tuple]
146-
split-on = '^(\d+)\.(\d+)\.(\d+)\.([a-zA-Z])(\d+)(?:.\d+)?'
147-
150+
[tool.versioningit.template-fields]
151+
method = { module = "scripts.versioning", value = "template_fields"}
148152

149153
[tool.versioningit.write]
150154
file = "disnake/_version.py"
@@ -163,11 +167,7 @@ class VersionInfo(NamedTuple):
163167
releaselevel: Literal["alpha", "beta", "candidate", "final"]
164168
serial: int
165169
166-
167-
# fmt: off
168-
version_info: VersionInfo = VersionInfo(*{version_tuple}[:5])
169-
# fmt: on
170-
170+
version_info: VersionInfo = VersionInfo{version_tuple}
171171
"""
172172

173173
[tool.ruff]
@@ -441,24 +441,3 @@ exclude_lines = [
441441
"^\\s*raise NotImplementedError$",
442442
"^\\s*\\.\\.\\.$",
443443
]
444-
445-
446-
[tool.check-manifest]
447-
ignore = [
448-
# CI
449-
".pre-commit-config.yaml",
450-
".readthedocs.yml",
451-
".libcst.codemod.yaml",
452-
"noxfile.py",
453-
# docs
454-
"CONTRIBUTING.md",
455-
"RELEASE.md",
456-
"assets/**",
457-
"changelog/**",
458-
"docs/**",
459-
"examples/**",
460-
# tests
461-
"test_bot/**",
462-
"tests/**",
463-
"scripts/**",
464-
]

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, Dict, Optional
5+
6+
import packaging.version
7+
import versioningit
8+
9+
10+
def template_fields(
11+
*,
12+
version: str,
13+
description: Optional[versioningit.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)