Skip to content

Commit 5696805

Browse files
feat: add partial dynamic versioning support (not yet backwards compat)
1 parent e2042dc commit 5696805

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-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
@@ -59,6 +59,8 @@ jobs:
5959
needs: lock-dependencies
6060
steps:
6161
- uses: actions/checkout@v4
62+
with:
63+
fetch-depth: '0'
6264

6365
- name: Set up environment
6466
uses: ./.github/actions/setup-env
@@ -126,6 +128,9 @@ jobs:
126128
needs: lock-dependencies
127129
steps:
128130
- uses: actions/checkout@v4
131+
with:
132+
fetch-depth: '0'
133+
129134

130135
- name: Set up environment
131136
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ __pypackages__/
3434
.pdm.toml
3535
.pdm-python
3636
pdm.lock
37+
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]
@@ -125,10 +125,47 @@ test = { cmd = "nox -Rs test --", help = "Run pytest" }
125125
include = [
126126
"disnake/",
127127
]
128+
artifacts = ["disnake/_version.py"]
128129

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

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

0 commit comments

Comments
 (0)