diff --git a/crates/puffin-cli/src/commands/pip_install.rs b/crates/puffin-cli/src/commands/pip_install.rs index 940d8f26c..8e6fed645 100644 --- a/crates/puffin-cli/src/commands/pip_install.rs +++ b/crates/puffin-cli/src/commands/pip_install.rs @@ -395,9 +395,9 @@ async fn install( let wheels = wheels.into_iter().chain(local).collect::>(); if !wheels.is_empty() { let start = std::time::Instant::now(); - puffin_installer::Installer::new(venv) + let reporter = InstallReporter::from(printer).with_length(wheels.len() as u64); + puffin_installer::Installer::new(venv, reporter) .with_link_mode(link_mode) - .with_reporter(InstallReporter::from(printer).with_length(wheels.len() as u64)) .install(&wheels)?; let s = if wheels.len() == 1 { "" } else { "s" }; diff --git a/crates/puffin-cli/src/commands/pip_sync.rs b/crates/puffin-cli/src/commands/pip_sync.rs index 159b40432..704a87ced 100644 --- a/crates/puffin-cli/src/commands/pip_sync.rs +++ b/crates/puffin-cli/src/commands/pip_sync.rs @@ -245,9 +245,9 @@ pub(crate) async fn sync_requirements( let wheels = wheels.into_iter().chain(local).collect::>(); if !wheels.is_empty() { let start = std::time::Instant::now(); - puffin_installer::Installer::new(&venv) + let reporter = InstallReporter::from(printer).with_length(wheels.len() as u64); + puffin_installer::Installer::new(&venv, reporter) .with_link_mode(link_mode) - .with_reporter(InstallReporter::from(printer).with_length(wheels.len() as u64)) .install(&wheels)?; let s = if wheels.len() == 1 { "" } else { "s" }; diff --git a/crates/puffin-dispatch/src/lib.rs b/crates/puffin-dispatch/src/lib.rs index b2ccc3ed1..2563053de 100644 --- a/crates/puffin-dispatch/src/lib.rs +++ b/crates/puffin-dispatch/src/lib.rs @@ -16,6 +16,7 @@ use platform_tags::Tags; use puffin_build::{BuildKind, SourceBuild, SourceBuildContext}; use puffin_cache::Cache; use puffin_client::RegistryClient; +use puffin_installer::InstallDummyReporter; use puffin_installer::{Downloader, InstallPlan, Installer, Reinstall}; use puffin_interpreter::{Interpreter, Virtualenv}; use puffin_resolver::{DistFinder, Manifest, ResolutionOptions, Resolver}; @@ -205,7 +206,7 @@ impl BuildContext for BuildDispatch { if wheels.len() == 1 { "" } else { "s" }, wheels.iter().map(ToString::to_string).join(", ") ); - Installer::new(venv) + Installer::new(venv, InstallDummyReporter) .install(&wheels) .context("Failed to install build dependencies")?; } @@ -214,7 +215,7 @@ impl BuildContext for BuildDispatch { }) } - #[instrument(skip_all, fields(source_dist = source_dist, subdirectory = ?subdirectory))] + #[instrument(skip_all, fields(source_dist = source_dist, subdirectory = ? subdirectory))] fn setup_build<'a>( &'a self, source: &'a Path, diff --git a/crates/puffin-installer/src/installer.rs b/crates/puffin-installer/src/installer.rs index 3ac49a0d1..173b17e4c 100644 --- a/crates/puffin-installer/src/installer.rs +++ b/crates/puffin-installer/src/installer.rs @@ -7,16 +7,16 @@ use puffin_interpreter::Virtualenv; pub struct Installer<'a> { venv: &'a Virtualenv, link_mode: install_wheel_rs::linker::LinkMode, - reporter: Option>, + reporter: Box, } impl<'a> Installer<'a> { /// Initialize a new installer. - pub fn new(venv: &'a Virtualenv) -> Self { + pub fn new(venv: &'a Virtualenv, reporter: impl Reporter + 'static) -> Self { Self { venv, link_mode: install_wheel_rs::linker::LinkMode::default(), - reporter: None, + reporter: Box::new(reporter), } } @@ -26,15 +26,6 @@ impl<'a> Installer<'a> { Self { link_mode, ..self } } - /// Set the [`Reporter`] to use for this installer. - #[must_use] - pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self { - Self { - reporter: Some(Box::new(reporter)), - ..self - } - } - /// Install a set of wheels into a Python virtual environment. pub fn install(self, wheels: &[CachedDist]) -> Result<()> { tokio::task::block_in_place(|| { @@ -57,9 +48,7 @@ impl<'a> Installer<'a> { ) .with_context(|| format!("Failed to install: {wheel}"))?; - if let Some(reporter) = self.reporter.as_ref() { - reporter.on_install_progress(wheel); - } + self.reporter.on_install_progress(wheel); Ok::<(), Error>(()) }) @@ -74,3 +63,10 @@ pub trait Reporter: Send + Sync { /// Callback to invoke when the resolution is complete. fn on_install_complete(&self); } + +pub struct DummyReporter; + +impl Reporter for DummyReporter { + fn on_install_progress(&self, _wheel: &CachedDist) {} + fn on_install_complete(&self) {} +} diff --git a/crates/puffin-installer/src/lib.rs b/crates/puffin-installer/src/lib.rs index 17c090bb0..bf4401341 100644 --- a/crates/puffin-installer/src/lib.rs +++ b/crates/puffin-installer/src/lib.rs @@ -1,5 +1,7 @@ pub use downloader::{Downloader, Reporter as DownloadReporter}; -pub use installer::{Installer, Reporter as InstallReporter}; +pub use installer::{ + DummyReporter as InstallDummyReporter, Installer, Reporter as InstallReporter, +}; pub use plan::{InstallPlan, Reinstall}; pub use site_packages::SitePackages; pub use uninstall::uninstall;