Skip to content

Commit f71e648

Browse files
feat: add partial dynamic versioning support (not yet backwards compat)
1 parent 467c9e5 commit f71e648

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
@@ -92,6 +92,8 @@ jobs:
9292
- lint
9393
steps:
9494
- uses: actions/checkout@v4
95+
with:
96+
fetch-depth: '0'
9597

9698
- name: Set up environment
9799
id: setup-env
@@ -171,6 +173,9 @@ jobs:
171173
- lint
172174
steps:
173175
- uses: actions/checkout@v4
176+
with:
177+
fetch-depth: '0'
178+
174179

175180
- name: Set up environment
176181
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.12.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=12, 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]
@@ -126,10 +126,47 @@ test = { cmd = "nox -Rs test --", help = "Run pytest" }
126126
include = [
127127
"disnake/",
128128
]
129+
artifacts = ["disnake/_version.py"]
129130

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

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

0 commit comments

Comments
 (0)