Skip to content

The agent that grows with you

test(pm): skip host-Python fixtures by what the prefix contains

etherneted76cbf9bbf4
diff --git a/tests/pm/test_cold_runtime_e2e.py b/tests/pm/test_cold_runtime_e2e.py
index 5f99e1b19d7..0c07cd983bd 100644
--- a/tests/pm/test_cold_runtime_e2e.py
+++ b/tests/pm/test_cold_runtime_e2e.py
@@ -52,6 +52,26 @@ def _bare(python, repo, code, *, env, expected=0):
)
+_UNSHIPPED = {"site-packages", "test", "__pycache__"}
+
+
+def _foreign_link(stdlib: Path) -> Path | None:
+ """First link in the shipped stdlib that the store's extractor refuses.
+
+ PM extracts archives with tarfile's data filter, which rejects absolute or
+ escaping links. Distro Pythons link stdlib files into /etc (Debian's
+ sitecustomize.py), so their stdlib cannot stand in for a standalone one.
+ """
+ for directory, dirnames, filenames in os.walk(stdlib):
+ dirnames[:] = [name for name in dirnames if name not in _UNSHIPPED]
+ for name in (*dirnames, *filenames):
+ path = Path(directory) / name
+ if path.is_symlink() and (os.path.isabs(os.readlink(path))
+ or not path.resolve().is_relative_to(stdlib)):
+ return path
+ return None
+
+
@pytest.mark.platforms("linux")
@pytest.mark.parametrize("bootstrap_name", [None, "python3.11"])
def test_cold_cli_builds_own_runtime_discovers_plugins_and_repairs_app(tmp_path, bootstrap_name):
@@ -68,8 +88,9 @@ def test_cold_cli_builds_own_runtime_discovers_plugins_and_repairs_app(tmp_path,
if sys.version_info[:2] != (3, 14):
pytest.skip("the checked-in PM runtime currently requires Python 3.14")
stdlib = next(d for d in (Path(sys.base_prefix) / "lib").glob("python3.*") if (d / "os.py").is_file())
- if (stdlib / "sitecustomize.py").is_symlink() and not (stdlib / "sitecustomize.py").resolve().is_relative_to(stdlib):
- pytest.skip("host Python stdlib has non-relocatable sitecustomize.py")
+ foreign = _foreign_link(stdlib)
+ if foreign is not None:
+ pytest.skip(f"host Python is not self-contained: {foreign} links outside its stdlib")
bootstrap_python = shutil.which(bootstrap_name) if bootstrap_name else python
if bootstrap_python is None:
pytest.skip(f"{bootstrap_name} must be on PATH for the legacy bootstrap test")
diff --git a/tests/pm/test_update_dependency_legs.py b/tests/pm/test_update_dependency_legs.py
index 1aa2f4cfa63..8ebae205b2e 100644
--- a/tests/pm/test_update_dependency_legs.py
+++ b/tests/pm/test_update_dependency_legs.py
@@ -53,6 +53,26 @@ def project(tmp_path, monkeypatch):
return repo, caller, lock
+def _shared_prefix(root: Path, *, limit: int = 50_000) -> str:
+ """Why ``root`` cannot be digested as a standalone Python package entry, or ''.
+
+ The fixture records the host interpreter's prefix as PM's Python entry,
+ which means reading every file under it. A distro prefix (/usr, /usr/local,
+ Homebrew) holds unrelated, sometimes unreadable, trees; a standalone or
+ self-contained build holds one interpreter.
+ """
+ count = 0
+ for directory, _, filenames in os.walk(root):
+ for name in filenames:
+ path = Path(directory) / name
+ count += 1
+ if count > limit:
+ return f'more than {limit} files'
+ if not path.is_symlink() and not os.access(path, os.R_OK):
+ return f'{path} is unreadable'
+ return ''
+
+
@pytest.mark.platforms('windows', 'posix')
def test_uv_refresh_uses_real_installed_tool_and_only_the_owned_project(tmp_path, monkeypatch, capsys):
repo, caller, lock = project(tmp_path, monkeypatch)
@@ -63,8 +83,9 @@ def test_uv_refresh_uses_real_installed_tool_and_only_the_owned_project(tmp_path
shutil.copy2(uv, managed)
python = Path(sys._base_executable).resolve()
python_root = python.parent if os.name == 'nt' else python.parents[1]
- if not python_root.is_relative_to(tmp_path) and python_root == Path('/usr'):
- pytest.skip("system Python prefix is not an isolated package fixture")
+ shared = _shared_prefix(python_root)
+ if shared:
+ pytest.skip(f"host Python prefix {python_root} is not self-contained: {shared}")
target = current_target()
facts = Facts(runtime / 'facts.json')
for name, package, entry in [('uv', Uv(), managed.parent), ('python', Python(), python_root)]: