From ae6cb5e33488f3e3b6de5cd2680273d30209d4db Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 26 Jun 2022 23:38:00 +0200 Subject: [PATCH] fix #727: correctly handle incomplete archivals from setuptools_scm_git_archival --- CHANGELOG.rst | 6 ++++++ src/setuptools_scm/git.py | 9 +++++++-- testing/test_git.py | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4c9bd248..f1405232 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +v7.0.4 +======= + +* fix #727: correctly handle incomplete archivals from setuptools_scm_git_archival +* fix #691: correctly handle specifying root in pyproject.toml + v7.0.3 ======= * fix mercurial usage when pip primes a isolated environment diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index 47e2a9e8..1aee95a1 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -276,7 +276,8 @@ def search_parent(dirname: _t.PathT) -> GitWorkdir | None: def archival_to_version( data: dict[str, str], config: Configuration | None = None -) -> ScmVersion: +) -> ScmVersion | None: + node: str | None trace("data", data) archival_describe = data.get("describe-name", DESCRIBE_UNSUPPORTED) if DESCRIBE_UNSUPPORTED in archival_describe: @@ -293,7 +294,11 @@ def archival_to_version( if versions: return meta(versions[0], config=config) else: - return meta("0.0", node=data.get("node"), config=config) + node = data.get("node") + if node is not None: + return meta("0.0", node=node, config=config) + else: + return None def parse_archival( diff --git a/testing/test_git.py b/testing/test_git.py index 6663527f..674d9042 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -529,9 +529,17 @@ def test_git_getdate_signed_commit(signed_commit_wd: WorkDir) -> None: def test_git_archival_to_version(expected: str, from_data: dict[str, str]) -> None: config = Configuration() version = archival_to_version(from_data, config=config) + assert version is not None assert ( format_version( version, version_scheme="guess-next-dev", local_scheme="node-and-date" ) == expected ) + + +@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/727") +def test_git_archival_node_missing_no_version() -> None: + config = Configuration() + version = archival_to_version({}, config=config) + assert version is None