mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Improve handling of invalid virtual environments during interpreter discovery (#8086)
## Summary Fix #8075. Invalid discovered environments in the working directory should be filtered out. ## Test Plan - Test python_find --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
624e79a8a9
commit
459269fc95
2 changed files with 75 additions and 3 deletions
|
@ -25,6 +25,7 @@ use crate::managed::ManagedPythonInstallations;
|
|||
use crate::microsoft_store::find_microsoft_store_pythons;
|
||||
#[cfg(windows)]
|
||||
use crate::py_launcher::{registry_pythons, WindowsPython};
|
||||
use crate::virtualenv::Error as VirtualEnvError;
|
||||
use crate::virtualenv::{
|
||||
conda_environment_from_env, virtualenv_from_env, virtualenv_from_working_dir,
|
||||
virtualenv_python_executable, CondaEnvironmentKind,
|
||||
|
@ -729,10 +730,27 @@ impl Error {
|
|||
false
|
||||
}
|
||||
InterpreterError::NotFound(path) => {
|
||||
trace!("Skipping missing interpreter at {}", path.display());
|
||||
false
|
||||
// If the interpreter is from an active, valid virtual environment, we should
|
||||
// fail because it's broken
|
||||
if let Some(Ok(true)) = matches!(source, PythonSource::ActiveEnvironment)
|
||||
.then(|| {
|
||||
path.parent()
|
||||
.and_then(Path::parent)
|
||||
.map(|path| path.join("pyvenv.cfg").try_exists())
|
||||
})
|
||||
.flatten()
|
||||
{
|
||||
true
|
||||
} else {
|
||||
trace!("Skipping missing interpreter at {}", path.display());
|
||||
false
|
||||
}
|
||||
}
|
||||
},
|
||||
Error::VirtualEnv(VirtualEnvError::MissingPyVenvCfg(path)) => {
|
||||
trace!("Skipping broken virtualenv at {}", path.display());
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue