diff --git a/crates/distribution-types/src/traits.rs b/crates/distribution-types/src/traits.rs index aeda3181b..9101403c4 100644 --- a/crates/distribution-types/src/traits.rs +++ b/crates/distribution-types/src/traits.rs @@ -159,3 +159,9 @@ impl std::fmt::Display for SourceDist { write!(f, "{}{}", self.name(), self.version_or_url()) } } + +impl std::fmt::Display for &dyn Metadata { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}{}", self.name(), self.version_or_url()) + } +} diff --git a/crates/puffin-cli/src/commands/reporters.rs b/crates/puffin-cli/src/commands/reporters.rs index e61951861..d5adea255 100644 --- a/crates/puffin-cli/src/commands/reporters.rs +++ b/crates/puffin-cli/src/commands/reporters.rs @@ -5,7 +5,7 @@ use colored::Colorize; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use url::Url; -use distribution_types::{CachedDist, Dist, Metadata, SourceDist, VersionOrUrl}; +use distribution_types::{CachedDist, Metadata, SourceDist, VersionOrUrl}; use puffin_normalize::PackageName; use crate::printer::Printer; @@ -35,8 +35,8 @@ impl FinderReporter { } impl puffin_resolver::FinderReporter for FinderReporter { - fn on_progress(&self, wheel: &Dist) { - self.progress.set_message(format!("{wheel}")); + fn on_progress(&self, dist: &dyn Metadata) { + self.progress.set_message(format!("{dist}")); self.progress.inc(1); } @@ -81,8 +81,8 @@ impl DownloadReporter { } impl puffin_installer::DownloadReporter for DownloadReporter { - fn on_progress(&self, wheel: &CachedDist) { - self.progress.set_message(format!("{wheel}")); + fn on_progress(&self, dist: &dyn Metadata) { + self.progress.set_message(format!("{dist}")); self.progress.inc(1); } @@ -90,7 +90,7 @@ impl puffin_installer::DownloadReporter for DownloadReporter { self.progress.finish_and_clear(); } - fn on_build_start(&self, dist: &SourceDist) -> usize { + fn on_build_start(&self, dist: &dyn Metadata) -> usize { let progress = self.multi_progress.insert_before( &self.progress, ProgressBar::with_draw_target(None, self.printer.target()), @@ -108,7 +108,7 @@ impl puffin_installer::DownloadReporter for DownloadReporter { bars.len() - 1 } - fn on_build_complete(&self, dist: &SourceDist, index: usize) { + fn on_build_complete(&self, dist: &dyn Metadata, index: usize) { let bars = self.bars.lock().unwrap(); let progress = &bars[index]; progress.finish_with_message(format!( @@ -231,7 +231,7 @@ impl puffin_resolver::ResolverReporter for ResolverReporter { self.progress.finish_and_clear(); } - fn on_build_start(&self, dist: &SourceDist) -> usize { + fn on_build_start(&self, dist: &dyn Metadata) -> usize { let progress = self.multi_progress.insert_before( &self.progress, ProgressBar::with_draw_target(None, self.printer.target()), @@ -249,7 +249,7 @@ impl puffin_resolver::ResolverReporter for ResolverReporter { bars.len() - 1 } - fn on_build_complete(&self, dist: &SourceDist, index: usize) { + fn on_build_complete(&self, dist: &dyn Metadata, index: usize) { let bars = self.bars.lock().unwrap(); let progress = &bars[index]; progress.finish_with_message(format!( @@ -296,7 +296,7 @@ trait ColorDisplay { fn to_color_string(&self) -> String; } -impl ColorDisplay for &Dist { +impl ColorDisplay for &dyn Metadata { fn to_color_string(&self) -> String { let name = self.name(); let version_or_url = self.version_or_url(); diff --git a/crates/puffin-installer/src/downloader.rs b/crates/puffin-installer/src/downloader.rs index 585f86512..93d41e76b 100644 --- a/crates/puffin-installer/src/downloader.rs +++ b/crates/puffin-installer/src/downloader.rs @@ -7,7 +7,7 @@ use tokio::task::JoinError; use tracing::{instrument, warn}; use url::Url; -use distribution_types::{CachedDist, Dist, RemoteSource, SourceDist}; +use distribution_types::{CachedDist, Dist, Metadata, RemoteSource, SourceDist}; use platform_tags::Tags; use puffin_cache::Cache; use puffin_client::RegistryClient; @@ -191,16 +191,16 @@ impl<'a, Context: BuildContext + Send + Sync> Downloader<'a, Context> { pub trait Reporter: Send + Sync { /// Callback to invoke when a wheel is unzipped. This implies that the wheel was downloaded and, /// if necessary, built. - fn on_progress(&self, wheel: &CachedDist); + fn on_progress(&self, dist: &dyn Metadata); /// Callback to invoke when the operation is complete. fn on_complete(&self); /// Callback to invoke when a source distribution build is kicked off. - fn on_build_start(&self, dist: &SourceDist) -> usize; + fn on_build_start(&self, dist: &dyn Metadata) -> usize; /// Callback to invoke when a source distribution build is complete. - fn on_build_complete(&self, dist: &SourceDist, id: usize); + fn on_build_complete(&self, dist: &dyn Metadata, id: usize); /// Callback to invoke when a repository checkout begins. fn on_checkout_start(&self, url: &Url, rev: &str) -> usize; diff --git a/crates/puffin-resolver/src/finder.rs b/crates/puffin-resolver/src/finder.rs index 8df87e360..217abb60f 100644 --- a/crates/puffin-resolver/src/finder.rs +++ b/crates/puffin-resolver/src/finder.rs @@ -8,7 +8,7 @@ use anyhow::Result; use futures::StreamExt; use rustc_hash::FxHashMap; -use distribution_types::Dist; +use distribution_types::{Dist, Metadata}; use pep440_rs::Version; use pep508_rs::{Requirement, VersionOrUrl}; use platform_tags::{TagPriority, Tags}; @@ -239,7 +239,7 @@ enum Response { pub trait Reporter: Send + Sync { /// Callback to invoke when a package is resolved to a specific distribution. - fn on_progress(&self, wheel: &Dist); + fn on_progress(&self, dist: &dyn Metadata); /// Callback to invoke when the resolution is complete. fn on_complete(&self); diff --git a/crates/puffin-resolver/src/resolver.rs b/crates/puffin-resolver/src/resolver.rs index 5c9635db6..38dc0092d 100644 --- a/crates/puffin-resolver/src/resolver.rs +++ b/crates/puffin-resolver/src/resolver.rs @@ -752,10 +752,10 @@ pub trait Reporter: Send + Sync { fn on_complete(&self); /// Callback to invoke when a source distribution build is kicked off. - fn on_build_start(&self, dist: &SourceDist) -> usize; + fn on_build_start(&self, dist: &dyn Metadata) -> usize; /// Callback to invoke when a source distribution build is complete. - fn on_build_complete(&self, dist: &SourceDist, id: usize); + fn on_build_complete(&self, dist: &dyn Metadata, id: usize); /// Callback to invoke when a repository checkout begins. fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;