From a030a466e666b3fbfab5348dd70fd24adb6a4251 Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 22 Nov 2023 11:38:10 +0100 Subject: [PATCH] Error before download with no_build (#487) This is fixes a performance regression where when `--no-build` was set, the fetcher would still download the source dist only to error afterwards. --- crates/puffin-distribution/src/fetcher.rs | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/puffin-distribution/src/fetcher.rs b/crates/puffin-distribution/src/fetcher.rs index 4e20c4351..ea426b20d 100644 --- a/crates/puffin-distribution/src/fetcher.rs +++ b/crates/puffin-distribution/src/fetcher.rs @@ -2,7 +2,7 @@ use std::path::Path; use std::str::FromStr; use std::sync::Arc; -use anyhow::Result; +use anyhow::{bail, Result}; use bytesize::ByteSize; use fs_err::tokio as fs; use tokio_util::compat::FuturesAsyncReadCompatExt; @@ -87,17 +87,23 @@ impl<'a> Fetcher<'a> { } // Fetch the distribution, then read the metadata (for built distributions), or build // the distribution and _then_ read the metadata (for source distributions). - dist => match self.fetch_dist(dist, client).await? { - Download::Wheel(wheel) => { - let metadata = wheel.read_dist_info()?; - Ok(metadata) + dist => { + // Optimization: Skip source dist download when we must not build them anyway + if build_context.no_build() && matches!(dist, Dist::Source(_)) { + bail!("Building source distributions is disabled"); } - Download::SourceDist(sdist) => { - let wheel = self.build_sdist(sdist, build_context).await?; - let metadata = wheel.read_dist_info()?; - Ok(metadata) + match self.fetch_dist(dist, client).await? { + Download::Wheel(wheel) => { + let metadata = wheel.read_dist_info()?; + Ok(metadata) + } + Download::SourceDist(sdist) => { + let wheel = self.build_sdist(sdist, build_context).await?; + let metadata = wheel.read_dist_info()?; + Ok(metadata) + } } - }, + } } }