From d497adaacb8d669a6ce85c1fbd6ccb10c5c473fe Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 10 Jul 2024 11:03:22 -0400 Subject: [PATCH] Improve 'any' search message during `uv python install` (#4940) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Special cases the `Any` request in output e.g., ``` ❯ cargo run -q -- python install --isolated warning: `uv python install` is experimental and may change without warning. Searching for Python installations Found existing installation: cpython-3.12.3-macos-aarch64-none Python is already available. Use `uv python install ` to install a specific version. ``` instead of ``` ❯ cargo run -q -- python install --isolated warning: `uv python install` is experimental and may change without warning. Searching for Python versions matching: any Python Found existing installation for any Python: cpython-3.12.3-macos-aarch64-none Python is already available. Use `uv python install ` to install a specific version. ``` --- crates/uv/src/commands/python/install.rs | 38 ++++++++++++++++-------- crates/uv/src/main.rs | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/uv/src/commands/python/install.rs b/crates/uv/src/commands/python/install.rs index dd9cf2471..c23a239f6 100644 --- a/crates/uv/src/commands/python/install.rs +++ b/crates/uv/src/commands/python/install.rs @@ -26,6 +26,7 @@ pub(crate) async fn install( native_tls: bool, connectivity: Connectivity, preview: PreviewMode, + isolated: bool, _cache: &Cache, printer: Printer, ) -> Result { @@ -41,7 +42,12 @@ pub(crate) async fn install( let targets = targets.into_iter().collect::>(); let requests: Vec<_> = if targets.is_empty() { - if let Some(requests) = requests_from_version_file().await? { + // Read from the version file, unless `isolated` was requested + if let Some(requests) = if isolated { + None + } else { + requests_from_version_file().await? + } { requests } else { vec![PythonRequest::Any] @@ -61,21 +67,29 @@ pub(crate) async fn install( let installed_installations: Vec<_> = installations.find_all()?.collect(); let mut unfilled_requests = Vec::new(); for (request, download_request) in requests.iter().zip(download_requests) { - writeln!( - printer.stderr(), - "Searching for Python versions matching: {}", - request.cyan() - )?; + if matches!(requests.as_slice(), [PythonRequest::Any]) { + writeln!(printer.stderr(), "Searching for Python installations")?; + } else { + writeln!( + printer.stderr(), + "Searching for Python versions matching: {}", + request.cyan() + )?; + } if let Some(installation) = installed_installations .iter() .find(|installation| download_request.satisfied_by_key(installation.key())) { - writeln!( - printer.stderr(), - "Found existing installation for {}: {}", - request.cyan(), - installation.key().green(), - )?; + if matches!(request, PythonRequest::Any) { + writeln!(printer.stderr(), "Found: {}", installation.key().green(),)?; + } else { + writeln!( + printer.stderr(), + "Found existing installation for {}: {}", + request.cyan(), + installation.key().green(), + )?; + } if force { writeln!( printer.stderr(), diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 523bf8006..0e33183ff 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -776,6 +776,7 @@ async fn run() -> Result { globals.native_tls, globals.connectivity, globals.preview, + globals.isolated, &cache, printer, )