From 7f497fa43fd14b120f46d3f8c350452cabef6c00 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 5 Oct 2023 00:48:21 -0400 Subject: [PATCH] Add progress bar --- crates/puffin-cli/Cargo.toml | 1 + crates/puffin-cli/src/commands/install.rs | 11 +++++++++-- crates/puffin-client/Cargo.toml | 1 + crates/puffin-client/src/api.rs | 2 +- requirements.txt | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/puffin-cli/Cargo.toml b/crates/puffin-cli/Cargo.toml index bc0509b8e..9d00cf125 100644 --- a/crates/puffin-cli/Cargo.toml +++ b/crates/puffin-cli/Cargo.toml @@ -24,3 +24,4 @@ pep440_rs = "0.3.12" tracing = "0.1.37" tracing-tree = "0.2.5" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +indicatif = "0.17.7" diff --git a/crates/puffin-cli/src/commands/install.rs b/crates/puffin-cli/src/commands/install.rs index 9d9f3db96..14cdbbfb8 100644 --- a/crates/puffin-cli/src/commands/install.rs +++ b/crates/puffin-cli/src/commands/install.rs @@ -13,14 +13,16 @@ use puffin_client::{File, PypiClientBuilder, SimpleJson}; use puffin_requirements::metadata::Metadata21; use puffin_requirements::package_name::PackageName; use puffin_requirements::wheel::WheelName; - +use indicatif::{ProgressBar, ProgressStyle}; use crate::commands::ExitStatus; +#[derive(Debug)] enum Request { Package(Requirement), Version(Requirement, File), } +#[derive(Debug)] enum Response { Package(SimpleJson, Requirement), Version(Metadata21, Requirement), @@ -66,7 +68,7 @@ pub(crate) async fn install(src: &Path) -> Result { ), Request::Version(requirement, file) => Either::Right( proxy_client - .file(file.clone()) + .file(file) .map_ok(move |metadata| Response::Version(metadata, requirement)), ), }) @@ -84,6 +86,10 @@ pub(crate) async fn install(src: &Path) -> Result { // Resolve the requirements. let mut resolution: HashMap = HashMap::with_capacity(requirements.len()); + let spinner_style = ProgressStyle::with_template("{spinner} {wide_bar} [{pos}/{len}] {msg}").unwrap(); + let bar = ProgressBar::new(8); + bar.set_style(spinner_style); + while let Some(chunk) = package_stream.next().await { for result in chunk { let result: Response = result?; @@ -125,6 +131,7 @@ pub(crate) async fn install(src: &Path) -> Result { let normalized_name = PackageName::normalize(&requirement.name); in_flight.remove(&normalized_name); resolution.insert(normalized_name, metadata.version); + bar.inc(1); // Enqueue its dependencies. for dependency in metadata.requires_dist { diff --git a/crates/puffin-client/Cargo.toml b/crates/puffin-client/Cargo.toml index a7bbfc38b..1c6cc28b6 100644 --- a/crates/puffin-client/Cargo.toml +++ b/crates/puffin-client/Cargo.toml @@ -17,3 +17,4 @@ serde_json = { version = "1.0.107" } thiserror = { version = "1.0.49" } url = { version = "2.4.1" } tracing = "0.1.37" +indicatif = "0.17.7" diff --git a/crates/puffin-client/src/api.rs b/crates/puffin-client/src/api.rs index 7c665f36e..24a440460 100644 --- a/crates/puffin-client/src/api.rs +++ b/crates/puffin-client/src/api.rs @@ -35,7 +35,7 @@ impl PypiClient { // Fetch from the registry. let text = self.simple_impl(&package_name, &url).await?; let payload = serde_json::from_str(&text) - .map_err(move |e| PypiClientError::from_json_err(e, "".to_string())); + .map_err(move |e| PypiClientError::from_json_err(e, String::new())); trace!("fetched metadata for {} in {:?}", url, start.elapsed()); diff --git a/requirements.txt b/requirements.txt index 7e1060246..7e66a17d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -flask +black