From 28721cf5fc5029fd2a9de9b05346e335b297c790 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 6 Oct 2023 00:50:13 -0400 Subject: [PATCH] Avoid caching wheel fetches --- crates/puffin-cli/src/commands/compile.rs | 2 +- crates/puffin-cli/src/commands/install.rs | 2 +- crates/puffin-client/src/api.rs | 3 +-- crates/puffin-client/src/client.rs | 10 +++++++++- crates/puffin-package/src/wheel.rs | 3 ++- crates/puffin-resolve/src/lib.rs | 1 - 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/puffin-cli/src/commands/compile.rs b/crates/puffin-cli/src/commands/compile.rs index d881bb5e1..87c9b8097 100644 --- a/crates/puffin-cli/src/commands/compile.rs +++ b/crates/puffin-cli/src/commands/compile.rs @@ -2,9 +2,9 @@ use std::path::Path; use std::str::FromStr; use anyhow::Result; -use puffin_client::PypiClientBuilder; use tracing::debug; +use puffin_client::PypiClientBuilder; use puffin_interpreter::PythonExecutable; use puffin_platform::tags::Tags; use puffin_platform::Platform; diff --git a/crates/puffin-cli/src/commands/install.rs b/crates/puffin-cli/src/commands/install.rs index 63ff460b9..c5e0a4a8a 100644 --- a/crates/puffin-cli/src/commands/install.rs +++ b/crates/puffin-cli/src/commands/install.rs @@ -3,10 +3,10 @@ use std::str::FromStr; use anyhow::Result; use async_std::fs::File; +use install_wheel_rs::{install_wheel, InstallLocation}; use tracing::debug; use url::Url; -use install_wheel_rs::{install_wheel, InstallLocation}; use puffin_client::PypiClientBuilder; use puffin_interpreter::PythonExecutable; use puffin_platform::tags::Tags; diff --git a/crates/puffin-client/src/api.rs b/crates/puffin-client/src/api.rs index 43c06c52c..255f7ae41 100644 --- a/crates/puffin-client/src/api.rs +++ b/crates/puffin-client/src/api.rs @@ -111,8 +111,7 @@ impl PypiClient { url: &Url, ) -> Result, PypiClientError> { Ok(Box::new( - // TODO(charlie): Use an uncached client. - self.client + self.uncached_client .get(url.to_string()) .send() .await? diff --git a/crates/puffin-client/src/client.rs b/crates/puffin-client/src/client.rs index c8e1ac4d6..6d0c14fc8 100644 --- a/crates/puffin-client/src/client.rs +++ b/crates/puffin-client/src/client.rs @@ -66,7 +66,7 @@ impl PypiClientBuilder { let retry_strategy = RetryTransientMiddleware::new_with_policy(retry_policy); let mut client_builder = - reqwest_middleware::ClientBuilder::new(client_raw).with(retry_strategy); + reqwest_middleware::ClientBuilder::new(client_raw.clone()).with(retry_strategy); if let Some(path) = self.cache { client_builder = client_builder.with(Cache(HttpCache { @@ -76,10 +76,17 @@ impl PypiClientBuilder { })); } + let retry_policy = ExponentialBackoff::builder().build_with_max_retries(self.retries); + let retry_strategy = RetryTransientMiddleware::new_with_policy(retry_policy); + + let uncached_client_builder = + reqwest_middleware::ClientBuilder::new(client_raw).with(retry_strategy); + PypiClient { registry: Arc::new(self.registry), proxy: Arc::new(self.proxy), client: client_builder.build(), + uncached_client: uncached_client_builder.build(), } } } @@ -89,4 +96,5 @@ pub struct PypiClient { pub(crate) registry: Arc, pub(crate) proxy: Arc, pub(crate) client: ClientWithMiddleware, + pub(crate) uncached_client: ClientWithMiddleware, } diff --git a/crates/puffin-package/src/wheel.rs b/crates/puffin-package/src/wheel.rs index 8a45c2044..7a2b807f5 100644 --- a/crates/puffin-package/src/wheel.rs +++ b/crates/puffin-package/src/wheel.rs @@ -1,8 +1,9 @@ use std::str::FromStr; -use puffin_platform::tags::Tags; use thiserror::Error; +use puffin_platform::tags::Tags; + #[derive(Debug, Clone, Eq, PartialEq)] pub struct WheelFilename { pub distribution: String, diff --git a/crates/puffin-resolve/src/lib.rs b/crates/puffin-resolve/src/lib.rs index 9ff32c2c7..25895f9cb 100644 --- a/crates/puffin-resolve/src/lib.rs +++ b/crates/puffin-resolve/src/lib.rs @@ -1,5 +1,4 @@ use std::collections::{HashMap, HashSet}; - use std::str::FromStr; use anyhow::Result;