From 74ca9128b459dcc210e6613d7e6053dfe3dbcef0 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 18 Dec 2023 09:42:58 -0500 Subject: [PATCH] Canonicalize virtualenv path once (#678) This avoids filesystem calls when creating a `BuildDispatch`. Co-authored-by: konsti --- crates/puffin-cli/src/commands/pip_compile.rs | 2 +- crates/puffin-cli/src/commands/pip_install.rs | 3 +-- crates/puffin-cli/src/commands/pip_sync.rs | 3 +-- crates/puffin-dev/src/build.rs | 2 +- crates/puffin-dev/src/resolve_cli.rs | 4 ++-- crates/puffin-dev/src/resolve_many.rs | 2 +- crates/puffin-interpreter/src/virtual_env.rs | 1 + 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/puffin-cli/src/commands/pip_compile.rs b/crates/puffin-cli/src/commands/pip_compile.rs index b2cc78b08..8d6fbcc6e 100644 --- a/crates/puffin-cli/src/commands/pip_compile.rs +++ b/crates/puffin-cli/src/commands/pip_compile.rs @@ -142,7 +142,7 @@ pub(crate) async fn pip_compile( client.clone(), cache.clone(), interpreter, - fs_err::canonicalize(venv.python_executable())?, + venv.python_executable(), no_build, index_urls, ) diff --git a/crates/puffin-cli/src/commands/pip_install.rs b/crates/puffin-cli/src/commands/pip_install.rs index a722152a9..79708b592 100644 --- a/crates/puffin-cli/src/commands/pip_install.rs +++ b/crates/puffin-cli/src/commands/pip_install.rs @@ -4,7 +4,6 @@ use std::path::Path; use anyhow::{anyhow, bail, Context, Result}; use chrono::{DateTime, Utc}; use colored::Colorize; -use fs_err as fs; use itertools::Itertools; use tempfile::tempdir_in; use tracing::debug; @@ -137,7 +136,7 @@ pub(crate) async fn pip_install( client.clone(), cache.clone(), interpreter, - fs::canonicalize(venv.python_executable())?, + venv.python_executable(), no_build, index_urls.clone(), ) diff --git a/crates/puffin-cli/src/commands/pip_sync.rs b/crates/puffin-cli/src/commands/pip_sync.rs index 49bf63b2c..f30bc3d0e 100644 --- a/crates/puffin-cli/src/commands/pip_sync.rs +++ b/crates/puffin-cli/src/commands/pip_sync.rs @@ -2,7 +2,6 @@ use std::fmt::Write; use anyhow::{bail, Context, Result}; use colored::Colorize; -use fs_err as fs; use itertools::Itertools; use tracing::debug; @@ -66,7 +65,7 @@ pub(crate) async fn pip_sync( client.clone(), cache.clone(), venv.interpreter().clone(), - fs::canonicalize(venv.python_executable())?, + venv.python_executable(), no_build, index_urls.clone(), ); diff --git a/crates/puffin-dev/src/build.rs b/crates/puffin-dev/src/build.rs index 84ba5f15b..67b9a598d 100644 --- a/crates/puffin-dev/src/build.rs +++ b/crates/puffin-dev/src/build.rs @@ -58,7 +58,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result { RegistryClientBuilder::new(cache.clone()).build(), cache, venv.interpreter().clone(), - fs::canonicalize(venv.python_executable())?, + venv.python_executable(), false, IndexUrls::default(), ); diff --git a/crates/puffin-dev/src/resolve_cli.rs b/crates/puffin-dev/src/resolve_cli.rs index 003860b35..1b8d92f7d 100644 --- a/crates/puffin-dev/src/resolve_cli.rs +++ b/crates/puffin-dev/src/resolve_cli.rs @@ -5,7 +5,7 @@ use anstream::println; use anyhow::{Context, Result}; use chrono::{DateTime, Utc}; use clap::{Parser, ValueEnum}; -use fs_err as fs; + use fs_err::File; use itertools::Itertools; use petgraph::dot::{Config as DotConfig, Dot}; @@ -55,7 +55,7 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> Result<()> { client.clone(), cache.clone(), venv.interpreter().clone(), - fs::canonicalize(venv.python_executable())?, + venv.python_executable(), args.no_build, IndexUrls::default(), ); diff --git a/crates/puffin-dev/src/resolve_many.rs b/crates/puffin-dev/src/resolve_many.rs index d0f76633d..4828b79af 100644 --- a/crates/puffin-dev/src/resolve_many.rs +++ b/crates/puffin-dev/src/resolve_many.rs @@ -56,7 +56,7 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> { RegistryClientBuilder::new(cache.clone()).build(), cache.clone(), venv.interpreter().clone(), - fs::canonicalize(venv.python_executable())?, + venv.python_executable(), args.no_build, IndexUrls::default(), ); diff --git a/crates/puffin-interpreter/src/virtual_env.rs b/crates/puffin-interpreter/src/virtual_env.rs index 97f9d7e3d..7a8f7234f 100644 --- a/crates/puffin-interpreter/src/virtual_env.rs +++ b/crates/puffin-interpreter/src/virtual_env.rs @@ -24,6 +24,7 @@ impl Virtualenv { let Some(venv) = detect_virtual_env(&platform)? else { return Err(Error::NotFound); }; + let venv = fs_err::canonicalize(venv)?; let executable = platform.venv_python(&venv); let interpreter = Interpreter::query(&executable, platform.0, cache)?;