Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit interpreter path during uv venv with managed Python #5311

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 21 additions & 10 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -150,21 +150,32 @@ async fn venv_impl(
Some(&reporter),
)
.await
.into_diagnostic()?
.into_interpreter();
.into_diagnostic()?;

let managed = python.source().is_managed();
Copy link
Member Author

@zanieb zanieb Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could check if this is a child of the managed Python directory but that seems more brittle.

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(),
Expand Down
Loading