From 81966c43dceaa22eb25a6c103897e9abf8002ac4 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 12 Feb 2025 12:45:59 -0600 Subject: [PATCH] Allow `--python ` 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 ` 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? --- crates/uv-python/src/discovery.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index f077f60f8..6c3b62f0d 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -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...