Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 24, 2024
1 parent ec4d2cc commit 0d953e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 1.2.2
_commit: 1.2.3
_src_path: gh:mkdocstrings/handler-template
author_email: dev@pawamoy.fr
author_fullname: Timothée Mazzucotelli
Expand Down
11 changes: 3 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ Discussions = "https://github.com/mkdocstrings/python/discussions"
Gitter = "https://gitter.im/mkdocstrings/python"
Funding = "https://github.com/sponsors/pawamoy"

[tool.pdm]
version = {source = "scm"}
[tool.pdm.version]
source = "call"
getter = "scripts.get_version:get_version"

[tool.pdm.build]
package-dir = "src"
Expand Down Expand Up @@ -75,12 +76,6 @@ data = [
{path = "share/**/*", relative-to = "."},
]

[tool.uv]
# Tell uv to ignore constraints on the main package.
# This is needed when the current project doesn't have Git tags (fork, CI).
override-dependencies = ["mkdocstrings-python"]
sources = { mkdocstrings-python = { workspace = true } }

[dependency-groups]
dev = [
# maintenance
Expand Down
27 changes: 27 additions & 0 deletions scripts/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Get current project version from Git tags or changelog."""

import re
from contextlib import suppress
from pathlib import Path

from pdm.backend.hooks.version import SCMVersion, Version, default_version_formatter, get_version_from_scm

_root = Path(__file__).parent.parent
_changelog = _root / "CHANGELOG.md"
_changelog_version_re = re.compile(r"^## \[(\d+\.\d+\.\d+)\].*$")
_default_scm_version = SCMVersion(Version("0.0.0"), None, False, None, None) # noqa: FBT003


def get_version() -> str:
"""Get current project version from Git tags or changelog."""
scm_version = get_version_from_scm(_root) or _default_scm_version
if scm_version.version <= Version("0.1"): # Missing Git tags?
with suppress(OSError, StopIteration): # noqa: SIM117
with _changelog.open("r", encoding="utf8") as file:
match = next(filter(None, map(_changelog_version_re.match, file)))
scm_version = scm_version._replace(version=Version(match.group(1)))
return default_version_formatter(scm_version)


if __name__ == "__main__":
print(get_version())

0 comments on commit 0d953e3

Please sign in to comment.