Skip to content

Commit c9186fd

Browse files
feat: add partial dynamic versioning support (not yet backwards compat)
1 parent 74d43ec commit c9186fd

File tree

7 files changed

+70
-19
lines changed

7 files changed

+70
-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

.github/workflows/lint-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858
needs: lock-dependencies
5959
steps:
6060
- uses: actions/checkout@v4
61+
with:
62+
fetch-depth: '0'
6163

6264
- name: Set up environment
6365
uses: ./.github/actions/setup-env
@@ -125,6 +127,9 @@ jobs:
125127
needs: lock-dependencies
126128
steps:
127129
- uses: actions/checkout@v4
130+
with:
131+
fetch-depth: '0'
132+
128133

129134
- name: Set up environment
130135
id: setup

.github/workflows/release.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: '0'
23+
2124

2225
- name: Set up environment
2326
id: setup

.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: 40 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]
@@ -124,10 +124,47 @@ test = { cmd = "nox -Rs test --", help = "Run pytest" }
124124
include = [
125125
"disnake/",
126126
]
127+
artifacts = ["disnake/_version.py"]
127128

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

132169
[tool.ruff]
133170
line-length = 100

0 commit comments

Comments
 (0)