From 67217358d6f0893841852121ceb7df93c5b22a14 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 20 Sep 2023 20:27:20 +0200 Subject: [PATCH] fix #912 - ensure mypy safe version template this also adds * a regression test running mypy (unpinned) * a regression tests running flake8 (unpinned) --- CHANGELOG.rst | 8 ++++++ .../_integration/dump_version.py | 2 ++ testing/test_functions.py | 28 ++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 72f46064..7aac3e7e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,11 @@ +v8.0.2 +====== + +bugfix +------ + +* fix #912: ensure mypy safety of the version template + regression test + v8.0.1 ====== diff --git a/src/setuptools_scm/_integration/dump_version.py b/src/setuptools_scm/_integration/dump_version.py index 421379bd..1dd280b9 100644 --- a/src/setuptools_scm/_integration/dump_version.py +++ b/src/setuptools_scm/_integration/dump_version.py @@ -15,6 +15,8 @@ ".py": """\ # file generated by setuptools_scm # don't change, don't track in version control +from __future__ import annotations + __version__ = version = {version!r} # type: str __version_tuple__ = version_tuple = {version_tuple!r} # type: tuple[int | str, ...] """, diff --git a/testing/test_functions.py b/testing/test_functions.py index dfc22b60..a9eb4f47 100644 --- a/testing/test_functions.py +++ b/testing/test_functions.py @@ -110,10 +110,7 @@ def test_dump_version_modern(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> assert target.read_text() == version -def test_dump_version_on_old_python(tmp_path: Path) -> None: - python37 = shutil.which("python3.7") - if python37 is None: - pytest.skip("python3.7 not found") +def dump_a_version(tmp_path: Path) -> None: from setuptools_scm._integration.dump_version import write_version_to_path version = "1.2.3" @@ -121,6 +118,13 @@ def test_dump_version_on_old_python(tmp_path: Path) -> None: write_version_to_path( tmp_path / "VERSION.py", template=None, version=version, scm_version=scm_version ) + + +def test_dump_version_on_old_python(tmp_path: Path) -> None: + python37 = shutil.which("python3.7") + if python37 is None: + pytest.skip("python3.7 not found") + dump_a_version(tmp_path) subprocess.run( [python37, "-c", "import VERSION;print(VERSION.version)"], cwd=tmp_path, @@ -128,6 +132,22 @@ def test_dump_version_on_old_python(tmp_path: Path) -> None: ) +def test_dump_version_mypy(tmp_path: Path) -> None: + mypy = shutil.which("mypy") + if mypy is None: + pytest.skip("mypy not found") + dump_a_version(tmp_path) + subprocess.run([mypy, "--strict", "VERSION.py"], cwd=tmp_path, check=True) + + +def test_dump_version_flake8(tmp_path: Path) -> None: + flake8 = shutil.which("flake8") + if flake8 is None: + pytest.skip("flake8 not found") + dump_a_version(tmp_path) + subprocess.run([flake8, "VERSION.py"], cwd=tmp_path, check=True) + + def test_has_command() -> None: with pytest.warns(RuntimeWarning, match="yadayada"): assert not has_command("yadayada_setuptools_aint_ne")