mirror of https://github.com/astral-sh/uv
Allow reporters to take `dyn Metadata` (#645)
This commit is contained in:
parent
1a62ca0c62
commit
eef9612719
|
|
@ -159,3 +159,9 @@ impl std::fmt::Display for SourceDist {
|
||||||
write!(f, "{}{}", self.name(), self.version_or_url())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use colored::Colorize;
|
||||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use distribution_types::{CachedDist, Dist, Metadata, SourceDist, VersionOrUrl};
|
use distribution_types::{CachedDist, Metadata, SourceDist, VersionOrUrl};
|
||||||
use puffin_normalize::PackageName;
|
use puffin_normalize::PackageName;
|
||||||
|
|
||||||
use crate::printer::Printer;
|
use crate::printer::Printer;
|
||||||
|
|
@ -35,8 +35,8 @@ impl FinderReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl puffin_resolver::FinderReporter for FinderReporter {
|
impl puffin_resolver::FinderReporter for FinderReporter {
|
||||||
fn on_progress(&self, wheel: &Dist) {
|
fn on_progress(&self, dist: &dyn Metadata) {
|
||||||
self.progress.set_message(format!("{wheel}"));
|
self.progress.set_message(format!("{dist}"));
|
||||||
self.progress.inc(1);
|
self.progress.inc(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,8 +81,8 @@ impl DownloadReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl puffin_installer::DownloadReporter for DownloadReporter {
|
impl puffin_installer::DownloadReporter for DownloadReporter {
|
||||||
fn on_progress(&self, wheel: &CachedDist) {
|
fn on_progress(&self, dist: &dyn Metadata) {
|
||||||
self.progress.set_message(format!("{wheel}"));
|
self.progress.set_message(format!("{dist}"));
|
||||||
self.progress.inc(1);
|
self.progress.inc(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ impl puffin_installer::DownloadReporter for DownloadReporter {
|
||||||
self.progress.finish_and_clear();
|
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(
|
let progress = self.multi_progress.insert_before(
|
||||||
&self.progress,
|
&self.progress,
|
||||||
ProgressBar::with_draw_target(None, self.printer.target()),
|
ProgressBar::with_draw_target(None, self.printer.target()),
|
||||||
|
|
@ -108,7 +108,7 @@ impl puffin_installer::DownloadReporter for DownloadReporter {
|
||||||
bars.len() - 1
|
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 bars = self.bars.lock().unwrap();
|
||||||
let progress = &bars[index];
|
let progress = &bars[index];
|
||||||
progress.finish_with_message(format!(
|
progress.finish_with_message(format!(
|
||||||
|
|
@ -231,7 +231,7 @@ impl puffin_resolver::ResolverReporter for ResolverReporter {
|
||||||
self.progress.finish_and_clear();
|
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(
|
let progress = self.multi_progress.insert_before(
|
||||||
&self.progress,
|
&self.progress,
|
||||||
ProgressBar::with_draw_target(None, self.printer.target()),
|
ProgressBar::with_draw_target(None, self.printer.target()),
|
||||||
|
|
@ -249,7 +249,7 @@ impl puffin_resolver::ResolverReporter for ResolverReporter {
|
||||||
bars.len() - 1
|
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 bars = self.bars.lock().unwrap();
|
||||||
let progress = &bars[index];
|
let progress = &bars[index];
|
||||||
progress.finish_with_message(format!(
|
progress.finish_with_message(format!(
|
||||||
|
|
@ -296,7 +296,7 @@ trait ColorDisplay {
|
||||||
fn to_color_string(&self) -> String;
|
fn to_color_string(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ColorDisplay for &Dist {
|
impl ColorDisplay for &dyn Metadata {
|
||||||
fn to_color_string(&self) -> String {
|
fn to_color_string(&self) -> String {
|
||||||
let name = self.name();
|
let name = self.name();
|
||||||
let version_or_url = self.version_or_url();
|
let version_or_url = self.version_or_url();
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use tokio::task::JoinError;
|
||||||
use tracing::{instrument, warn};
|
use tracing::{instrument, warn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use distribution_types::{CachedDist, Dist, RemoteSource, SourceDist};
|
use distribution_types::{CachedDist, Dist, Metadata, RemoteSource, SourceDist};
|
||||||
use platform_tags::Tags;
|
use platform_tags::Tags;
|
||||||
use puffin_cache::Cache;
|
use puffin_cache::Cache;
|
||||||
use puffin_client::RegistryClient;
|
use puffin_client::RegistryClient;
|
||||||
|
|
@ -191,16 +191,16 @@ impl<'a, Context: BuildContext + Send + Sync> Downloader<'a, Context> {
|
||||||
pub trait Reporter: Send + Sync {
|
pub trait Reporter: Send + Sync {
|
||||||
/// Callback to invoke when a wheel is unzipped. This implies that the wheel was downloaded and,
|
/// Callback to invoke when a wheel is unzipped. This implies that the wheel was downloaded and,
|
||||||
/// if necessary, built.
|
/// if necessary, built.
|
||||||
fn on_progress(&self, wheel: &CachedDist);
|
fn on_progress(&self, dist: &dyn Metadata);
|
||||||
|
|
||||||
/// Callback to invoke when the operation is complete.
|
/// Callback to invoke when the operation is complete.
|
||||||
fn on_complete(&self);
|
fn on_complete(&self);
|
||||||
|
|
||||||
/// Callback to invoke when a source distribution build is kicked off.
|
/// 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.
|
/// 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.
|
/// Callback to invoke when a repository checkout begins.
|
||||||
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;
|
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use anyhow::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use distribution_types::Dist;
|
use distribution_types::{Dist, Metadata};
|
||||||
use pep440_rs::Version;
|
use pep440_rs::Version;
|
||||||
use pep508_rs::{Requirement, VersionOrUrl};
|
use pep508_rs::{Requirement, VersionOrUrl};
|
||||||
use platform_tags::{TagPriority, Tags};
|
use platform_tags::{TagPriority, Tags};
|
||||||
|
|
@ -239,7 +239,7 @@ enum Response {
|
||||||
|
|
||||||
pub trait Reporter: Send + Sync {
|
pub trait Reporter: Send + Sync {
|
||||||
/// Callback to invoke when a package is resolved to a specific distribution.
|
/// 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.
|
/// Callback to invoke when the resolution is complete.
|
||||||
fn on_complete(&self);
|
fn on_complete(&self);
|
||||||
|
|
|
||||||
|
|
@ -752,10 +752,10 @@ pub trait Reporter: Send + Sync {
|
||||||
fn on_complete(&self);
|
fn on_complete(&self);
|
||||||
|
|
||||||
/// Callback to invoke when a source distribution build is kicked off.
|
/// 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.
|
/// 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.
|
/// Callback to invoke when a repository checkout begins.
|
||||||
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;
|
fn on_checkout_start(&self, url: &Url, rev: &str) -> usize;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue