diff --git a/crates/puffin-cli/src/commands/pip_sync.rs b/crates/puffin-cli/src/commands/pip_sync.rs index 88a808e3a..40bf14d1c 100644 --- a/crates/puffin-cli/src/commands/pip_sync.rs +++ b/crates/puffin-cli/src/commands/pip_sync.rs @@ -149,16 +149,16 @@ pub(crate) async fn sync_requirements( .with_reporter(DownloadReporter::from(printer).with_length(remote.len() as u64)); let downloads = downloader - .download(&remote, cache.unwrap_or(staging.path())) + .download(remote, cache.unwrap_or(staging.path())) .await?; - let s = if remote.len() == 1 { "" } else { "s" }; + let s = if downloads.len() == 1 { "" } else { "s" }; writeln!( printer, "{}", format!( "Downloaded {} in {}", - format!("{} package{}", remote.len(), s).bold(), + format!("{} package{}", downloads.len(), s).bold(), elapsed(start.elapsed()) ) .dimmed() diff --git a/crates/puffin-dispatch/src/lib.rs b/crates/puffin-dispatch/src/lib.rs index e91592cf5..33a0e3f4b 100644 --- a/crates/puffin-dispatch/src/lib.rs +++ b/crates/puffin-dispatch/src/lib.rs @@ -149,7 +149,7 @@ impl BuildContext for BuildDispatch { remote.iter().map(ToString::to_string).join(", ") ); Downloader::new(&self.client, self.cache.as_deref()) - .download(&remote, self.cache.as_deref().unwrap_or(staging.path())) + .download(remote, self.cache.as_deref().unwrap_or(staging.path())) .await .context("Failed to download build dependencies")? }; diff --git a/crates/puffin-installer/src/downloader.rs b/crates/puffin-installer/src/downloader.rs index d36d2968c..961a6f414 100644 --- a/crates/puffin-installer/src/downloader.rs +++ b/crates/puffin-installer/src/downloader.rs @@ -1,3 +1,4 @@ +use std::cmp::Reverse; use std::path::Path; use anyhow::Result; @@ -42,13 +43,17 @@ impl<'a> Downloader<'a> { /// Install a set of wheels into a Python virtual environment. pub async fn download( &'a self, - wheels: &'a [RemoteDistribution], + wheels: Vec, target: &'a Path, ) -> Result> { // Create the wheel cache subdirectory, if necessary. let wheel_cache = WheelCache::new(target); wheel_cache.init()?; + // Sort the wheels by size. + let mut wheels = wheels; + wheels.sort_unstable_by_key(|wheel| Reverse(wheel.file().size)); + // Phase 1: Fetch the wheels in parallel. let mut fetches = JoinSet::new(); let mut downloads = Vec::with_capacity(wheels.len()); diff --git a/crates/puffin-installer/src/unzipper.rs b/crates/puffin-installer/src/unzipper.rs index 746ed575b..b1dff00d0 100644 --- a/crates/puffin-installer/src/unzipper.rs +++ b/crates/puffin-installer/src/unzipper.rs @@ -1,3 +1,4 @@ +use std::cmp::Reverse; use std::path::Path; use anyhow::Result; @@ -38,6 +39,10 @@ impl Unzipper { let wheel_cache = WheelCache::new(target); wheel_cache.init()?; + // Sort the wheels by size. + let mut downloads = downloads; + downloads.sort_unstable_by_key(|wheel| Reverse(wheel.buffer.len())); + let staging = tempfile::tempdir_in(wheel_cache.root())?; // Unpack the wheels into the cache.