Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display download and installation completion using Reporter #3099

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/uv-installer/src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ impl<'a> Installer<'a> {

Ok::<(), Error>(())
})
})
})?;

if let Some(reporter) = self.reporter.as_ref() {
reporter.on_install_complete();
}
Comment on lines +79 to +81
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never called this apparently.


Ok(())
}
}

Expand Down
27 changes: 0 additions & 27 deletions crates/uv/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ async fn install(
let wheels = if remote.is_empty() {
vec![]
} else {
let start = std::time::Instant::now();

let downloader = Downloader::new(cache, tags, hasher, client, build_dispatch)
.with_reporter(DownloadReporter::from(printer).with_length(remote.len() as u64));

Expand All @@ -749,18 +747,6 @@ async fn install(
.await
.context("Failed to download distributions")?;

let s = if wheels.len() == 1 { "" } else { "s" };
writeln!(
printer.stderr(),
"{}",
format!(
"Downloaded {} in {}",
format!("{} package{}", wheels.len(), s).bold(),
elapsed(start.elapsed())
)
.dimmed()
)?;

wheels
};

Expand Down Expand Up @@ -794,23 +780,10 @@ async fn install(
// Install the resolved distributions.
let wheels = wheels.into_iter().chain(cached).collect::<Vec<_>>();
if !wheels.is_empty() {
let start = std::time::Instant::now();
uv_installer::Installer::new(venv)
.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" };
writeln!(
printer.stderr(),
"{}",
format!(
"Installed {} in {}",
format!("{} package{}", wheels.len(), s).bold(),
elapsed(start.elapsed())
)
.dimmed()
)?;
}

if compile {
Expand Down
43 changes: 41 additions & 2 deletions crates/uv/src/commands/reporters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Write;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::time::{Duration, Instant};

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use owo_colors::OwoColorize;
Expand All @@ -11,6 +12,7 @@ use distribution_types::{
};
use uv_normalize::PackageName;

use crate::commands::elapsed;
use crate::printer::Printer;

#[derive(Debug)]
Expand All @@ -19,6 +21,7 @@ pub(crate) struct DownloadReporter {
multi_progress: MultiProgress,
progress: ProgressBar,
bars: Arc<Mutex<Vec<ProgressBar>>>,
start_time: Instant,
}

impl From<Printer> for DownloadReporter {
Expand All @@ -36,6 +39,8 @@ impl From<Printer> for DownloadReporter {
multi_progress,
progress,
bars: Arc::new(Mutex::new(Vec::new())),
// TODO(zanieb): Consider setting the start time on the start of the first download insteasd
start_time: Instant::now(),
}
}
}
Expand Down Expand Up @@ -78,6 +83,20 @@ impl uv_installer::DownloadReporter for DownloadReporter {

fn on_complete(&self) {
self.progress.finish_and_clear();
if let Some(length) = self.progress.length() {
let s = if length == 1 { "" } else { "s" };
writeln!(
self.printer.stderr(),
"{}",
format!(
"Downloaded {} in {}",
format!("{} package{}", length, s).bold(),
elapsed(self.start_time.elapsed())
)
.dimmed()
)
.unwrap();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the progress bar implementation get around this? Do they just eat errors?

};
}

fn on_build_start(&self, source: &BuildableSource) -> usize {
Expand Down Expand Up @@ -130,7 +149,9 @@ impl uv_installer::DownloadReporter for DownloadReporter {

#[derive(Debug)]
pub(crate) struct InstallReporter {
printer: Printer,
progress: ProgressBar,
start_time: Instant,
}

impl From<Printer> for InstallReporter {
Expand All @@ -140,7 +161,11 @@ impl From<Printer> for InstallReporter {
ProgressStyle::with_template("{bar:20} [{pos}/{len}] {wide_msg:.dim}").unwrap(),
);
progress.set_message("Installing wheels...");
Self { progress }
Self {
printer,
progress,
start_time: Instant::now(),
}
}
}

Expand All @@ -160,6 +185,20 @@ impl uv_installer::InstallReporter for InstallReporter {

fn on_install_complete(&self) {
self.progress.finish_and_clear();
if let Some(length) = self.progress.length() {
let s = if length == 1 { "" } else { "s" };
writeln!(
self.printer.stderr(),
"{}",
format!(
"Installed {} in {}",
format!("{} package{}", length, s).bold(),
elapsed(self.start_time.elapsed())
)
.dimmed()
)
.unwrap();
};
}
}

Expand Down