Skip to content

Commit 0d953e3

Browse files
committed
chore: Template upgrade
1 parent ec4d2cc commit 0d953e3

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

.copier-answers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 1.2.2
2+
_commit: 1.2.3
33
_src_path: gh:mkdocstrings/handler-template
44
author_email: dev@pawamoy.fr
55
author_fullname: Timothée Mazzucotelli

pyproject.toml

+3-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ Discussions = "https://github.com/mkdocstrings/python/discussions"
4545
Gitter = "https://gitter.im/mkdocstrings/python"
4646
Funding = "https://github.com/sponsors/pawamoy"
4747

48-
[tool.pdm]
49-
version = {source = "scm"}
48+
[tool.pdm.version]
49+
source = "call"
50+
getter = "scripts.get_version:get_version"
5051

5152
[tool.pdm.build]
5253
package-dir = "src"
@@ -75,12 +76,6 @@ data = [
7576
{path = "share/**/*", relative-to = "."},
7677
]
7778

78-
[tool.uv]
79-
# Tell uv to ignore constraints on the main package.
80-
# This is needed when the current project doesn't have Git tags (fork, CI).
81-
override-dependencies = ["mkdocstrings-python"]
82-
sources = { mkdocstrings-python = { workspace = true } }
83-
8479
[dependency-groups]
8580
dev = [
8681
# maintenance

scripts/get_version.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Get current project version from Git tags or changelog."""
2+
3+
import re
4+
from contextlib import suppress
5+
from pathlib import Path
6+
7+
from pdm.backend.hooks.version import SCMVersion, Version, default_version_formatter, get_version_from_scm
8+
9+
_root = Path(__file__).parent.parent
10+
_changelog = _root / "CHANGELOG.md"
11+
_changelog_version_re = re.compile(r"^## \[(\d+\.\d+\.\d+)\].*$")
12+
_default_scm_version = SCMVersion(Version("0.0.0"), None, False, None, None) # noqa: FBT003
13+
14+
15+
def get_version() -> str:
16+
"""Get current project version from Git tags or changelog."""
17+
scm_version = get_version_from_scm(_root) or _default_scm_version
18+
if scm_version.version <= Version("0.1"): # Missing Git tags?
19+
with suppress(OSError, StopIteration): # noqa: SIM117
20+
with _changelog.open("r", encoding="utf8") as file:
21+
match = next(filter(None, map(_changelog_version_re.match, file)))
22+
scm_version = scm_version._replace(version=Version(match.group(1)))
23+
return default_version_formatter(scm_version)
24+
25+
26+
if __name__ == "__main__":
27+
print(get_version())

0 commit comments

Comments
 (0)