Always use base interpreter for cached environments (#4805)

Closes #4801.
This commit is contained in:
Charlie Marsh 2024-07-04 13:38:53 -04:00 committed by GitHub
parent 6a27135a65
commit 445d45b82c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 4 deletions

View file

@ -140,6 +140,25 @@ impl Interpreter {
}
}
/// Return the [`Interpreter`] for the base executable, if it's available.
///
/// If no such base executable is available, or if the base executable is the same as the
/// current executable, this method returns `None`.
pub fn to_base_interpreter(&self, cache: &Cache) -> Result<Option<Self>, Error> {
if let Some(base_executable) = self
.sys_base_executable()
.filter(|base_executable| *base_executable != self.sys_executable())
{
match Self::query(base_executable, cache) {
Ok(base_interpreter) => Ok(Some(base_interpreter)),
Err(Error::NotFound(_)) => Ok(None),
Err(err) => Err(err),
}
} else {
Ok(None)
}
}
/// Returns the path to the Python virtual environment.
#[inline]
pub fn platform(&self) -> &Platform {