Consolidate PythonPreference enforcement (#18567)

This commit is contained in:
Zanie Blue
2026-03-19 10:01:03 -05:00
committed by GitHub
parent bd2e0c9b09
commit d7da792648
5 changed files with 105 additions and 110 deletions
+15
View File
@@ -38,6 +38,14 @@ pub struct PythonInstallation {
}
impl PythonInstallation {
/// Create a new [`PythonInstallation`] from a source and interpreter.
pub fn new(source: PythonSource, interpreter: Interpreter) -> Self {
Self {
source,
interpreter,
}
}
/// Find an installed [`PythonInstallation`].
///
/// This is the standard interface for discovering a Python installation for creating
@@ -350,6 +358,13 @@ impl PythonInstallation {
LenientImplementationName::from(self.interpreter.implementation_name())
}
/// Returns `true` if this is a managed (uv-installed) Python installation.
///
/// Uses the source as a fast path, then falls back to checking the interpreter's base prefix.
pub fn is_managed(&self) -> bool {
self.source.is_managed() || self.interpreter.is_managed()
}
/// Whether this is a CPython installation.
///
/// Returns false if it is an alternative implementation, e.g., PyPy.