Update uv run and uv tool run to use Toolchain::find (#4134)

Extends https://github.com/astral-sh/uv/pull/4121
This commit is contained in:
Zanie Blue 2024-06-07 15:28:59 -04:00 committed by GitHub
parent 53035d65a1
commit 0f4f3b4714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View file

@ -108,11 +108,15 @@ pub(crate) async fn run(
// Discover an interpreter.
let interpreter = if let Some(project_env) = &project_env {
project_env.interpreter().clone()
} else if let Some(python) = python.as_ref() {
Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)?
.into_interpreter()
} else {
Toolchain::find_default(preview, cache)?.into_interpreter()
// Note we force preview on during `uv run` for now since the entire interface is in preview
Toolchain::find(
python.as_deref(),
SystemPython::Allowed,
PreviewMode::Enabled,
cache,
)?
.into_interpreter()
};
// TODO(charlie): If the environment satisfies the requirements, skip creation.

View file

@ -52,13 +52,16 @@ pub(crate) async fn run(
debug!("Syncing ephemeral environment.");
// Discover an interpreter.
let interpreter = if let Some(python) = python.as_ref() {
Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)?.into_interpreter()
} else {
Toolchain::find_default(preview, cache)?.into_interpreter()
};
// Note we force preview on during `uv tool run` for now since the entire interface is in preview
let interpreter = Toolchain::find(
python.as_deref(),
SystemPython::Allowed,
PreviewMode::Enabled,
cache,
)?
.into_interpreter();
// Create a virtual environment
// Create a virtual environment1
// TODO(zanieb): Move this path derivation elsewhere
let uv_state_path = std::env::current_dir()?.join(".uv");
fs_err::create_dir_all(&uv_state_path)?;