From 4b2b2d2870b8d4149fa6e3a48a9beea0009db734 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 7 Aug 2024 19:31:43 -0400 Subject: [PATCH] Use cached environments for `--with` layers (#5897) ## Summary I think this will make the logging changes a little easier by having more consistency between codepaths. --- crates/uv/src/commands/project/run.rs | 58 +++++++++++++-------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 0da9643e0..79089e88c 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -453,40 +453,38 @@ pub(crate) async fn run( // "installed" packages, so that we can skip re-installing them in the ephemeral // environment. - // Create a virtual environment - temp_dir = cache.environment()?; - let venv = uv_virtualenv::create_venv( - temp_dir.path(), - interpreter, - uv_virtualenv::Prompt::None, - false, - false, - false, - )?; - - match spec { - None => Some(venv), - Some(spec) if spec.is_empty() => Some(venv), + Some(match spec.filter(|spec| !spec.is_empty()) { + None => { + // Create a virtual environment + temp_dir = cache.environment()?; + uv_virtualenv::create_venv( + temp_dir.path(), + interpreter, + uv_virtualenv::Prompt::None, + false, + false, + false, + )? + } Some(spec) => { debug!("Syncing ephemeral requirements"); - // Install the ephemeral requirements. - Some( - project::update_environment( - venv, - spec, - &settings, - &state, - preview, - connectivity, - concurrency, - native_tls, - cache, - printer.filter(show_resolution), - ) - .await?, + + CachedEnvironment::get_or_create( + spec, + interpreter, + &settings, + &state, + preview, + connectivity, + concurrency, + native_tls, + cache, + printer.filter(show_resolution), ) + .await? + .into() } - } + }) }; // If we're running in an ephemeral environment, add a `sitecustomize.py` to enable loading of