diff --git a/Cargo.lock b/Cargo.lock index ab2f6dc5f..069153a10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2334,6 +2334,7 @@ dependencies = [ name = "puffin-cli" version = "0.0.1" dependencies = [ + "anstream", "anyhow", "assert_cmd", "assert_fs", @@ -2414,6 +2415,7 @@ dependencies = [ name = "puffin-dev" version = "0.0.1" dependencies = [ + "anstream", "anyhow", "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index b0b1eb6a8..60f6a3d3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ authors = ["Astral Software Inc. "] license = "MIT OR Apache-2.0" [workspace.dependencies] +anstream = { version = "0.6.4" } anyhow = { version = "1.0.75" } async_http_range_reader = { git = "https://github.com/baszalmstra/async_http_range_reader", rev = "8dab2c08ac864fec1df014465264f9a7c8eae905" } async_zip = { version = "0.0.15", features = ["tokio", "deflate"] } diff --git a/crates/puffin-cli/Cargo.toml b/crates/puffin-cli/Cargo.toml index 29795f32d..f3024652b 100644 --- a/crates/puffin-cli/Cargo.toml +++ b/crates/puffin-cli/Cargo.toml @@ -32,6 +32,7 @@ requirements-txt = { path = "../requirements-txt" } puffin-resolver = { path = "../puffin-resolver", features = ["clap"] } puffin-workspace = { path = "../puffin-workspace" } +anstream = { workspace = true } anyhow = { workspace = true } bitflags = { workspace = true } cacache = { workspace = true } diff --git a/crates/puffin-cli/src/commands/pip_compile.rs b/crates/puffin-cli/src/commands/pip_compile.rs index b943db706..881943f1e 100644 --- a/crates/puffin-cli/src/commands/pip_compile.rs +++ b/crates/puffin-cli/src/commands/pip_compile.rs @@ -1,13 +1,13 @@ +use anstream::AutoStream; use std::borrow::Cow; use std::fmt::Write; -use std::io::{stdout, BufWriter}; +use std::io::stdout; use std::path::Path; use std::str::FromStr; use std::{env, fs}; use anyhow::{anyhow, Result}; use colored::Colorize; -use fs_err::File; use itertools::Itertools; use tracing::debug; @@ -182,14 +182,10 @@ pub(crate) async fn pip_compile( .dimmed() )?; - if output_file.is_some() { - colored::control::set_override(false); - } - let mut writer: Box = if let Some(output_file) = output_file { - Box::new(BufWriter::new(File::create(output_file)?)) + Box::new(AutoStream::auto(fs::File::create(output_file)?)) } else { - Box::new(stdout()) + Box::new(AutoStream::auto(stdout())) }; writeln!( @@ -205,10 +201,6 @@ pub(crate) async fn pip_compile( )?; write!(writer, "{resolution}")?; - if output_file.is_some() { - colored::control::unset_override(); - } - Ok(ExitStatus::Success) } diff --git a/crates/puffin-cli/src/printer.rs b/crates/puffin-cli/src/printer.rs index 6cd53fb8d..2c400d241 100644 --- a/crates/puffin-cli/src/printer.rs +++ b/crates/puffin-cli/src/printer.rs @@ -1,3 +1,4 @@ +use anstream::eprint; use indicatif::ProgressDrawTarget; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -26,7 +27,7 @@ impl std::fmt::Write for Printer { fn write_str(&mut self, s: &str) -> std::fmt::Result { match self { Self::Default | Self::Verbose => { - #[allow(clippy::print_stderr)] + #[allow(clippy::print_stderr, clippy::ignored_unit_patterns)] { eprint!("{s}"); } diff --git a/crates/puffin-dev/Cargo.toml b/crates/puffin-dev/Cargo.toml index 0c99d4f67..b15932b28 100644 --- a/crates/puffin-dev/Cargo.toml +++ b/crates/puffin-dev/Cargo.toml @@ -23,6 +23,7 @@ puffin-interpreter = { path = "../puffin-interpreter" } pypi-types = { path = "../pypi-types" } puffin-traits = { path = "../puffin-traits" } +anstream = { workspace = true } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } colored = { workspace = true } diff --git a/crates/puffin-dev/src/resolve_cli.rs b/crates/puffin-dev/src/resolve_cli.rs index 41289f6aa..62aa1b51e 100644 --- a/crates/puffin-dev/src/resolve_cli.rs +++ b/crates/puffin-dev/src/resolve_cli.rs @@ -1,6 +1,7 @@ use std::fs; use std::path::PathBuf; +use anstream::println; use clap::Parser; use directories::ProjectDirs; use itertools::Itertools; @@ -46,8 +47,12 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> anyhow::Result<()> { let mut resolution = build_dispatch.resolve(&args.requirements).await?; resolution.sort_unstable_by(|a, b| a.name.cmp(&b.name)); + // Concise format for dev - println!("{}", resolution.iter().map(ToString::to_string).join(" ")); + #[allow(clippy::print_stderr, clippy::ignored_unit_patterns)] + { + println!("{}", resolution.iter().map(ToString::to_string).join(" ")); + } Ok(()) }