Skip to content

Commit

Permalink
Merge pull request #876 from RonnyPfannschmidt/fix-5227-typed-version…
Browse files Browse the repository at this point in the history
…-template

fix #527: add type annotations for version file template
  • Loading branch information
RonnyPfannschmidt authored Jul 12, 2023
2 parents 6ca645e + defc575 commit e9cbb5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ features

* support passing log levels to SETUPTOOLS_SCM_DEBUG
* support using rich.logging as console log handler if installed

* fix #527: type annotation in default version template

v7.1.0
======
Expand Down
7 changes: 5 additions & 2 deletions src/setuptools_scm/_integration/dump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
".py": """\
# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = {version!r}
__version_tuple__ = version_tuple = {version_tuple!r}
from __future__ import annotations
__version__ : str = version : str = {version!r}
__version_tuple__ : 'tuple[int | str, ...]' = \\
version_tuple : 'tuple[int | str, ...]' = {version_tuple!r}
""",
".txt": "{version}",
}
Expand All @@ -32,6 +34,7 @@ def dump_version(
assert isinstance(version, str)
# todo: assert write_to doesnt escape
write_to = Path(write_to)

assert not write_to.is_absolute(), f"{write_to=}"
target = Path(root).joinpath(write_to)
write_version_to_path(
Expand Down
7 changes: 5 additions & 2 deletions testing/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ def read(name: str) -> str:
scm_version = meta("1.0", distance=42, config=c)
dump_version(tmp_path, version, "first.py", scm_version=scm_version)
lines = read("first.py").splitlines()
assert "__version__ = version = '1.0.dev42'" in lines
assert "__version_tuple__ = version_tuple = (1, 0, 'dev42')" in lines
assert lines[3:] == [
"__version__ : str = version : str = '1.0.dev42'",
"__version_tuple__ : 'tuple[int | str, ...]' = \\",
" version_tuple : 'tuple[int | str, ...]' = (1, 0, 'dev42')",
]

version = "1.0.1+g4ac9d2c"
scm_version = meta("1.0.1", node="g4ac9d2c", config=c)
Expand Down

0 comments on commit e9cbb5a

Please sign in to comment.