From 8b16ce991e97c1d51e3187acf83f94c2fe125ac7 Mon Sep 17 00:00:00 2001 From: JulianFP Date: Thu, 24 Jul 2025 21:04:45 +0200 Subject: [PATCH 1/2] Add commit_id to dump_file function in addition to version --- .../_integration/dump_version.py | 8 +++++- testing/test_basic_api.py | 25 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/setuptools_scm/_integration/dump_version.py b/src/setuptools_scm/_integration/dump_version.py index a7bfcae7..9e2c4617 100644 --- a/src/setuptools_scm/_integration/dump_version.py +++ b/src/setuptools_scm/_integration/dump_version.py @@ -16,7 +16,7 @@ # file generated by setuptools-scm # don't change, don't track in version control -__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"] +__all__ = ["__version__", "__version_tuple__", "version", "version_tuple", "__commit_id__", "commit_id"] TYPE_CHECKING = False if TYPE_CHECKING: @@ -24,16 +24,22 @@ from typing import Union VERSION_TUPLE = Tuple[Union[int, str], ...] + COMMIT_ID = Union[str, None] else: VERSION_TUPLE = object + COMMIT_ID = object version: str __version__: str __version_tuple__: VERSION_TUPLE version_tuple: VERSION_TUPLE +commit_id: COMMIT_ID +__commit_id__: COMMIT_ID __version__ = version = {version!r} __version_tuple__ = version_tuple = {version_tuple!r} + +__commit_id__ = commit_id = {scm_version.node!r} """, ".txt": "{version}", } diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py index 76239841..dd7224e5 100644 --- a/testing/test_basic_api.py +++ b/testing/test_basic_api.py @@ -184,17 +184,30 @@ 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 lines[-2:] == [ + assert lines[-4:] == [ "__version__ = version = '1.0.dev42'", "__version_tuple__ = version_tuple = (1, 0, 'dev42')", + "", + "__commit_id__ = commit_id = None" + ] + + version = "1.0.1" + scm_version = meta("1.0.1", node="g4ac9d2c", config=c) + dump_version(tmp_path, version, "second.py", scm_version=scm_version) + lines = read("second.py").splitlines() + assert lines[-4:] == [ + "__version__ = version = '1.0.1'", + "__version_tuple__ = version_tuple = (1, 0, 1)", + "", + "__commit_id__ = commit_id = 'g4ac9d2c'" ] version = "1.0.1+g4ac9d2c" scm_version = meta("1.0.1", node="g4ac9d2c", config=c) dump_version( - tmp_path, version, "second.py", scm_version=scm_version, template=template + tmp_path, version, "third.py", scm_version=scm_version, template=template ) - lines = read("second.py").splitlines() + lines = read("third.py").splitlines() assert "__version__ = version = '1.0.1+g4ac9d2c'" in lines assert "__version_tuple__ = version_tuple = (1, 0, 1, 'g4ac9d2c')" in lines assert "__sha__ = 'g4ac9d2c'" in lines @@ -204,9 +217,9 @@ def read(name: str) -> str: "1.2.3", node="gb366d8b", distance=18, node_date=date(2021, 4, 15), config=c ) dump_version( - tmp_path, version, "third.py", scm_version=scm_version, template=template + tmp_path, version, "fourth.py", scm_version=scm_version, template=template ) - lines = read("third.py").splitlines() + lines = read("fourth.py").splitlines() assert "__version__ = version = '1.2.3.dev18+gb366d8b.d20210415'" in lines assert ( "__version_tuple__ = version_tuple = (1, 2, 3, 'dev18', 'gb366d8b.d20210415')" @@ -216,7 +229,7 @@ def read(name: str) -> str: import ast - ast.parse(read("third.py")) + ast.parse(read("fourth.py")) def test_parse_plain_fails(recwarn: pytest.WarningsRecorder) -> None: From 9217df2761fc40b64ceee09a7573fe448699c4b2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Jul 2025 10:26:08 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- testing/test_basic_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py index dd7224e5..2dbe2292 100644 --- a/testing/test_basic_api.py +++ b/testing/test_basic_api.py @@ -188,7 +188,7 @@ def read(name: str) -> str: "__version__ = version = '1.0.dev42'", "__version_tuple__ = version_tuple = (1, 0, 'dev42')", "", - "__commit_id__ = commit_id = None" + "__commit_id__ = commit_id = None", ] version = "1.0.1" @@ -199,7 +199,7 @@ def read(name: str) -> str: "__version__ = version = '1.0.1'", "__version_tuple__ = version_tuple = (1, 0, 1)", "", - "__commit_id__ = commit_id = 'g4ac9d2c'" + "__commit_id__ = commit_id = 'g4ac9d2c'", ] version = "1.0.1+g4ac9d2c"