Skip to content

Commit 06958fb

Browse files
Merge pull request #907 from RonnyPfannschmidt/fix-905-version-file-syntax-compat
fix #905 - correct version file template for older python versions
2 parents b5dbba7 + 597ba88 commit 06958fb

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2+
v8.0.1
3+
======
4+
5+
bugfix
6+
------
7+
8+
* update version file template to work on older python versions by using type comments
9+
110
v8.0.0
211
======
312

src/setuptools_scm/_integration/dump_version.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
".py": """\
1616
# file generated by setuptools_scm
1717
# don't change, don't track in version control
18-
from __future__ import annotations
19-
__version__ : str = version : str = {version!r}
20-
__version_tuple__ : 'tuple[int | str, ...]' = \\
21-
version_tuple : 'tuple[int | str, ...]' = {version_tuple!r}
18+
__version__ = version = {version!r} # type: str
19+
__version_tuple__ = version_tuple = {version_tuple!r} # type: tuple[int | str, ...]
2220
""",
2321
".txt": "{version}",
2422
}

testing/test_basic_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def read(name: str) -> str:
179179
scm_version = meta("1.0", distance=42, config=c)
180180
dump_version(tmp_path, version, "first.py", scm_version=scm_version)
181181
lines = read("first.py").splitlines()
182-
assert lines[3:] == [
183-
"__version__ : str = version : str = '1.0.dev42'",
184-
"__version_tuple__ : 'tuple[int | str, ...]' = \\",
185-
" version_tuple : 'tuple[int | str, ...]' = (1, 0, 'dev42')",
182+
assert lines[-2:] == [
183+
"__version__ = version = '1.0.dev42' # type: str",
184+
"__version_tuple__ = version_tuple = (1, 0, 'dev42')"
185+
" # type: tuple[int | str, ...]",
186186
]
187187

188188
version = "1.0.1+g4ac9d2c"

testing/test_functions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import shutil
4+
import subprocess
35
from pathlib import Path
46

57
import pytest
@@ -108,6 +110,24 @@ def test_dump_version_modern(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) ->
108110
assert target.read_text() == version
109111

110112

113+
def test_dump_version_on_old_python(tmp_path: Path) -> None:
114+
python37 = shutil.which("python3.7")
115+
if python37 is None:
116+
pytest.skip("python3.7 not found")
117+
from setuptools_scm._integration.dump_version import write_version_to_path
118+
119+
version = "1.2.3"
120+
scm_version = meta(version, config=c)
121+
write_version_to_path(
122+
tmp_path / "VERSION.py", template=None, version=version, scm_version=scm_version
123+
)
124+
subprocess.run(
125+
[python37, "-c", "import VERSION;print(VERSION.version)"],
126+
cwd=tmp_path,
127+
check=True,
128+
)
129+
130+
111131
def test_has_command() -> None:
112132
with pytest.warns(RuntimeWarning, match="yadayada"):
113133
assert not has_command("yadayada_setuptools_aint_ne")

0 commit comments

Comments
 (0)