Allow --python <dir> requests to match existing environments if sys.executable is the same file (#11290)

Closes https://github.com/astral-sh/uv/issues/11288

I tested the reproduction there manually.

I'm a little uncertain about this behavior, it's not true to the spirit
of `--python <dir>` selecting a target environment but this method is
only used to see if an existing environment matches for the purpose of
invalidation in projects and tools where I think we always force a
separate environment anyway?
This commit is contained in:
Zanie Blue 2025-02-12 12:45:59 -06:00 committed by GitHub
parent 3f6a7f9879
commit 81966c43dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1476,8 +1476,12 @@ impl PythonRequest {
version_request.matches_interpreter(interpreter)
}
PythonRequest::Directory(directory) => {
// `sys.prefix` points to the venv root.
// `sys.prefix` points to the environment root or `sys.executable` is the same
is_same_executable(directory, interpreter.sys_prefix())
|| is_same_executable(
virtualenv_python_executable(directory).as_path(),
interpreter.sys_executable(),
)
}
PythonRequest::File(file) => {
// The interpreter satisfies the request both if it is the venv...