Include all site packages directories in ephemeral environment overlays (#15121)

Related to https://github.com/astral-sh/uv/issues/15113

The case in the linked issue is that we perhaps should not be allowing
`uv run --with` with system interpreters at all. I think we can consider
that, but the issue highlighted that `uv run --with` for a system
interpreter is broken if the base interpreter has custom site packages.
This generalizes beyond system interpreters so we should probably fix
our overlays.
This commit is contained in:
Zanie Blue 2025-08-08 13:49:21 -05:00 committed by GitHub
parent f6a9b55eb7
commit bdb4b061db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 54 additions and 13 deletions

View file

@ -4,6 +4,7 @@ Queries information about the current Python interpreter and prints it as JSON.
The script will exit with status 0 on known error that are turned into rust errors.
"""
import site
import sys
import json
@ -637,6 +638,7 @@ def main() -> None:
# temporary path to `sys.path` so we can import it, which we have to strip later
# to avoid having this now-deleted path around.
"sys_path": sys.path[1:],
"site_packages": site.getsitepackages(),
"stdlib": sysconfig.get_path("stdlib"),
# Prior to the introduction of `sysconfig` patching, python-build-standalone installations would always use
# "/install" as the prefix. With `sysconfig` patching, we rewrite the prefix to match the actual installation