Add `UV_PYTHON_EXTRA_INSTALL_DIRS`

This commit is contained in:
Jo 2025-10-10 16:02:07 +08:00
parent ea5a09215b
commit 4b69fde81b
No known key found for this signature in database
3 changed files with 67 additions and 53 deletions

View File

@ -339,8 +339,15 @@ fn python_executables_from_installed<'a>(
preference: PythonPreference,
preview: Preview,
) -> Box<dyn Iterator<Item = Result<(PythonSource, PathBuf), Error>> + 'a> {
let from_managed_installations = iter::once_with(move || {
ManagedPythonInstallations::from_settings(None)
let extra_managed_install_dirs = env::var_os(EnvVars::UV_PYTHON_EXTRA_INSTALL_DIRS)
.into_iter()
.flat_map(|value| env::split_paths(&value).collect::<Vec<_>>())
.filter(|path| !path.as_os_str().is_empty());
let from_managed_installations = iter::once(None)
.chain(extra_managed_install_dirs.into_iter().map(Some))
.map(move |install_dir| {
ManagedPythonInstallations::from_settings(install_dir)
.map_err(Error::from)
.and_then(|installed_installations| {
debug!(

View File

@ -262,7 +262,7 @@ impl ManagedPythonInstallations {
) -> Result<impl DoubleEndedIterator<Item = ManagedPythonInstallation> + use<>, Error> {
let platform = Platform::from_env()?;
let iter = Self::from_settings(None)?
let iter = self
.find_all()?
.filter(move |installation| {
if !platform.supports(installation.platform()) {

View File

@ -371,6 +371,13 @@ impl EnvVars {
#[attr_added_in("0.2.22")]
pub const UV_PYTHON_INSTALL_DIR: &'static str = "UV_PYTHON_INSTALL_DIR";
/// Specifies additional directories to search for managed Python installations.
///
/// Directories should be separated by the platform-specific path separator, i.e.,
/// `:` on Unix and `;` on Windows.
#[attr_added_in("next release")]
pub const UV_PYTHON_EXTRA_INSTALL_DIRS: &'static str = "UV_PYTHON_EXTRA_INSTALL_DIRS";
/// Whether to install the Python executable into the `UV_PYTHON_BIN_DIR` directory.
#[attr_added_in("0.8.0")]
pub const UV_PYTHON_INSTALL_BIN: &'static str = "UV_PYTHON_INSTALL_BIN";