From 9a7324a243135974546f5005e8b864206b157ab4 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 22 Jul 2024 16:07:59 -0500 Subject: [PATCH] Omit interpreter path during `uv venv` with managed Python --- crates/uv-python/src/discovery.rs | 6 ++++++ crates/uv/src/commands/venv.rs | 31 +++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 81f8f93bc588..a94b7e8e2f48 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -1244,6 +1244,12 @@ impl PythonRequest { } } +impl PythonSource { + pub fn is_managed(&self) -> bool { + matches!(self, Self::Managed) + } +} + impl PythonPreference { fn allows(self, source: PythonSource) -> bool { // If not dealing with a system interpreter source, we don't care about the preference diff --git a/crates/uv/src/commands/venv.rs b/crates/uv/src/commands/venv.rs index f980ec752c95..e0e6626c7932 100644 --- a/crates/uv/src/commands/venv.rs +++ b/crates/uv/src/commands/venv.rs @@ -140,7 +140,7 @@ async fn venv_impl( } // Locate the Python interpreter to use in the environment - let interpreter = PythonInstallation::find_or_fetch( + let python = PythonInstallation::find_or_fetch( interpreter_request, EnvironmentPreference::OnlySystem, python_preference, @@ -150,21 +150,32 @@ async fn venv_impl( Some(&reporter), ) .await - .into_diagnostic()? - .into_interpreter(); + .into_diagnostic()?; + + let managed = python.source().is_managed(); + let interpreter = python.into_interpreter(); // Add all authenticated sources to the cache. for url in index_locations.urls() { store_credentials_from_url(url); } - writeln!( - printer.stderr(), - "Using Python {} interpreter at: {}", - interpreter.python_version(), - interpreter.sys_executable().user_display().cyan() - ) - .into_diagnostic()?; + if managed { + writeln!( + printer.stderr(), + "Using Python {}", + interpreter.python_version().cyan() + ) + .into_diagnostic()?; + } else { + writeln!( + printer.stderr(), + "Using Python {} interpreter at: {}", + interpreter.python_version(), + interpreter.sys_executable().user_display().cyan() + ) + .into_diagnostic()?; + } writeln!( printer.stderr(),