Skip to content

Commit 535f5ff

Browse files
RonnyPfannschmidtCursor AIclaude
committed
fix: move PKG-INFO discovery tests to setuptools-scm (#1446)
These tests depend on the pkginfo entry point registered by setuptools-scm. Running vcs-versioning tests without setuptools-scm installed caused them to fail. Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4 <claude@anthropic.com>
1 parent 0cde123 commit 535f5ff

5 files changed

Lines changed: 55 additions & 48 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move PKG-INFO discovery tests from vcs-versioning to setuptools-scm where the entry points are registered.

‎setuptools-scm/pyproject.toml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ setuptools_scm = "setuptools_scm._integration.setuptools:infer_version"
103103
pkginfo = "setuptools_scm._integration._discover:discover_pkginfo"
104104
egg-info = "setuptools_scm._integration._discover:discover_egg_info_metadata"
105105

106-
# VCS-related entry points are now provided by vcs-versioning package
107-
# Only file-finder entry points remain in setuptools_scm
108-
109106
[tool.setuptools.packages.find]
110107
where = ["src"]
111108
namespaces = false
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Tests for PKG-INFO discovery (depends on setuptools-scm entry points)."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
from vcs_versioning._config import Configuration
10+
from vcs_versioning._fallback_workdir import PkgInfoWorkdir
11+
from vcs_versioning._worktree_discovery import discover_workdir
12+
13+
14+
def test_discovers_pkginfo(tmp_path: Path) -> None:
15+
(tmp_path / "PKG-INFO").write_text(
16+
"Metadata-Version: 2.1\nName: pkg\nVersion: 3.0.0\n",
17+
encoding="utf-8",
18+
)
19+
config = Configuration(relative_to=str(tmp_path / "pyproject.toml"))
20+
result = discover_workdir(config)
21+
assert result is not None
22+
assert isinstance(result, PkgInfoWorkdir)
23+
24+
25+
@pytest.mark.issue(1431)
26+
def test_unprocessed_archival_falls_through_to_pkginfo(tmp_path: Path) -> None:
27+
"""Unprocessed .git_archival.txt must not shadow a valid PKG-INFO.
28+
29+
PyPI sdists contain both files: a .git_archival.txt with raw
30+
``$Format:...`` placeholders (never substituted because the sdist
31+
was built by setuptools, not ``git archive``) and a PKG-INFO with
32+
the correct version. Before the fix, the archival fallback was
33+
stashed as the sole candidate and its ``get_scm_version()`` returned
34+
None, causing a LookupError.
35+
"""
36+
(tmp_path / ".git_archival.txt").write_text(
37+
"node: $Format:%H$\n"
38+
"node-date: $Format:%cI$\n"
39+
"describe-name: $Format:%(describe:tags=true)$\n"
40+
"ref-names: $Format:%D$\n",
41+
encoding="utf-8",
42+
)
43+
(tmp_path / "PKG-INFO").write_text(
44+
"Metadata-Version: 2.1\nName: my-pkg\nVersion: 1.2.3\n",
45+
encoding="utf-8",
46+
)
47+
config = Configuration(relative_to=str(tmp_path / "pyproject.toml"))
48+
result = discover_workdir(config)
49+
assert result is not None
50+
assert isinstance(result, PkgInfoWorkdir)
51+
version = result.get_scm_version()
52+
assert version is not None
53+
assert str(version.tag) == "1.2.3"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move PKG-INFO discovery tests to setuptools-scm where the entry points are registered.

‎vcs-versioning/testing_vcs/test_workdir_discovery.py‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from vcs_versioning._fallback_workdir import (
1212
ArchivedWorkdir,
1313
MetadataWorkdir,
14-
PkgInfoWorkdir,
1514
StaticWorkdir,
1615
)
1716
from vcs_versioning._scm_metadata import (
@@ -130,16 +129,6 @@ def test_list_tracked_files_scoped_to_project_root(self, tmp_path: Path) -> None
130129

131130

132131
class TestDiscoverWorkdirFallback:
133-
def test_discovers_pkginfo(self, tmp_path: Path) -> None:
134-
(tmp_path / "PKG-INFO").write_text(
135-
"Metadata-Version: 2.1\nName: pkg\nVersion: 3.0.0\n",
136-
encoding="utf-8",
137-
)
138-
config = Configuration(relative_to=str(tmp_path / "pyproject.toml"))
139-
result = discover_workdir(config)
140-
assert result is not None
141-
assert isinstance(result, PkgInfoWorkdir)
142-
143132
def test_discovers_git_archival(self, tmp_path: Path) -> None:
144133
(tmp_path / ".git_archival.txt").write_text(
145134
"node: abc1234\nref-names: HEAD\n",
@@ -219,40 +208,6 @@ def test_mismatched_project_path_raises(self, tmp_path: Path) -> None:
219208
discover_workdir(config)
220209

221210

222-
class TestFallbackPriority:
223-
@pytest.mark.issue(1431)
224-
def test_unprocessed_archival_falls_through_to_pkginfo(
225-
self, tmp_path: Path
226-
) -> None:
227-
"""Unprocessed .git_archival.txt must not shadow a valid PKG-INFO.
228-
229-
PyPI sdists contain both files: a .git_archival.txt with raw
230-
``$Format:...`` placeholders (never substituted because the sdist
231-
was built by setuptools, not ``git archive``) and a PKG-INFO with
232-
the correct version. Before the fix, the archival fallback was
233-
stashed as the sole candidate and its ``get_scm_version()`` returned
234-
None, causing a LookupError.
235-
"""
236-
(tmp_path / ".git_archival.txt").write_text(
237-
"node: $Format:%H$\n"
238-
"node-date: $Format:%cI$\n"
239-
"describe-name: $Format:%(describe:tags=true)$\n"
240-
"ref-names: $Format:%D$\n",
241-
encoding="utf-8",
242-
)
243-
(tmp_path / "PKG-INFO").write_text(
244-
"Metadata-Version: 2.1\nName: my-pkg\nVersion: 1.2.3\n",
245-
encoding="utf-8",
246-
)
247-
config = Configuration(relative_to=str(tmp_path / "pyproject.toml"))
248-
result = discover_workdir(config)
249-
assert result is not None
250-
assert isinstance(result, PkgInfoWorkdir)
251-
version = result.get_scm_version()
252-
assert version is not None
253-
assert str(version.tag) == "1.2.3"
254-
255-
256211
class TestFallbackWorkdirDiscoveryFactories:
257212
def test_discover_archival_git(self, tmp_path: Path) -> None:
258213
from vcs_versioning._fallback_workdir import discover_archival

0 commit comments

Comments
 (0)