Skip to content

Commit 34b3023

Browse files
feat: add partial dynamic versioning support (not yet backwards compat)
1 parent b6c6a05 commit 34b3023

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# force LF for pyproject to make hashFiles in CI consistent (windows <3)
22
# (see https://github.com/actions/runner/issues/498)
3-
pyproject.toml text eol=lf
3+
pyproject.toml text eol=lf export-subst

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ __pypackages__/
3636
pdm.lock
3737

3838
!test_bot/locale/*.json
39+
40+
disnake/_version.py

disnake/__init__.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
__author__ = "Rapptz, EQUENOS"
1515
__license__ = "MIT"
1616
__copyright__ = "Copyright 2015-present Rapptz, 2021-present EQUENOS"
17-
__version__ = "2.11.0a"
1817

1918
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
2019

2120
import logging
22-
from typing import Literal, NamedTuple
2321

2422
from . import abc as abc, opus as opus, ui as ui, utils as utils # explicitly re-export modules
23+
from ._version import (
24+
VersionInfo, # pyright: ignore[reportUnusedImport] # noqa: F401
25+
__version__, # noqa: F401
26+
version_info, # pyright: ignore[reportUnusedImport] # noqa: F401
27+
)
2528
from .activity import *
2629
from .app_commands import *
2730
from .appinfo import *
@@ -77,17 +80,4 @@
7780
from .welcome_screen import *
7881
from .widget import *
7982

80-
81-
class VersionInfo(NamedTuple):
82-
major: int
83-
minor: int
84-
micro: int
85-
releaselevel: Literal["alpha", "beta", "candidate", "final"]
86-
serial: int
87-
88-
89-
# fmt: off
90-
version_info: VersionInfo = VersionInfo(major=2, minor=11, micro=0, releaselevel="alpha", serial=0)
91-
# fmt: on
92-
9383
logging.getLogger(__name__).addHandler(logging.NullHandler())

disnake/_version.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
from typing import Literal, NamedTuple
4+
5+
__version__: str
6+
7+
class VersionInfo(NamedTuple):
8+
major: int
9+
minor: int
10+
micro: int
11+
releaselevel: Literal["alpha", "beta", "candidate", "final"]
12+
serial: int
13+
14+
version_info: VersionInfo

pyproject.toml

Lines changed: 41 additions & 3 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"]
4+
requires = ["hatchling", "versioningit>=3.3.0"]
55
build-backend = "hatchling.build"
66

77
[project]
@@ -74,6 +74,7 @@ tools = [
7474
"python-dotenv~=1.0.0",
7575
"check-manifest==0.49",
7676
"ruff==0.9.3",
77+
"versioningit>=3.3.0",
7778
]
7879
changelog = [
7980
"towncrier==23.6.0",
@@ -131,10 +132,47 @@ test = { cmd = "test", help = "Run pytest" }
131132
include = [
132133
"disnake/",
133134
]
135+
artifacts = ["disnake/_version.py"]
134136

135137
[tool.hatch.version]
136-
path = "disnake/__init__.py"
137-
pattern = '__version__ = "(?P<version>.+)"'
138+
source = "versioningit"
139+
140+
[tool.versioningit.vcs]
141+
method = "git-archive"
142+
describe-subst = "$Format:%(describe:tags,match=v*)$"
143+
144+
[tool.versioningit.format]
145+
distance = "{base_version}+{distance}.{vcs}{rev}"
146+
dirty = "{base_version}+d{build_date:%Y%m%d}"
147+
distance-dirty = "{base_version}.a{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"
148+
149+
[tool.versioningit.template-fields.version-tuple]
150+
split-on = '^(\d+)\.(\d+)\.(\d+)\.([a-zA-Z])(\d+)(?:.\d+)?'
151+
152+
153+
[tool.versioningit.write]
154+
file = "disnake/_version.py"
155+
template = """
156+
# SPDX-License-Identifier: MIT
157+
158+
from typing import Literal, NamedTuple
159+
160+
__version__ = "{version}"
161+
162+
163+
class VersionInfo(NamedTuple):
164+
major: int
165+
minor: int
166+
micro: int
167+
releaselevel: Literal["alpha", "beta", "candidate", "final"]
168+
serial: int
169+
170+
171+
# fmt: off
172+
version_info: VersionInfo = VersionInfo(*{version_tuple}[:5])
173+
# fmt: on
174+
175+
"""
138176

139177
[tool.ruff]
140178
line-length = 100

0 commit comments

Comments
 (0)