Skip to content

Modify pip list and tree to print to stdout regardless of the --quiet flag #8392

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions crates/uv/src/commands/pip/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp::max;
use std::fmt::Write;

use anstream::println;
use anyhow::Result;
use itertools::Itertools;
use owo_colors::OwoColorize;
Expand Down Expand Up @@ -56,7 +57,7 @@ pub(crate) fn pip_list(
ListFormat::Json => {
let rows = results.iter().copied().map(Entry::from).collect_vec();
let output = serde_json::to_string(&rows)?;
writeln!(printer.stdout(), "{output}")?;
println!("{output}");
}
ListFormat::Columns if results.is_empty() => {}
ListFormat::Columns => {
Expand Down Expand Up @@ -97,18 +98,13 @@ pub(crate) fn pip_list(
}

for elems in MultiZip(columns.iter().map(Column::fmt).collect_vec()) {
writeln!(printer.stdout(), "{}", elems.join(" ").trim_end())?;
println!("{}", elems.join(" ").trim_end());
}
}
ListFormat::Freeze if results.is_empty() => {}
ListFormat::Freeze => {
for dist in &results {
writeln!(
printer.stdout(),
"{}=={}",
dist.name().bold(),
dist.version()
)?;
println!("{}=={}", dist.name().bold(), dist.version());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/uv/src/commands/project/tree.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use std::fmt::Write;
use std::path::Path;

use anstream::print;
use anyhow::Result;

use uv_cache::Cache;
use uv_client::Connectivity;
use uv_configuration::{Concurrency, DevMode, LowerBound, TargetTriple};
Expand Down Expand Up @@ -100,7 +101,7 @@ pub(crate) async fn tree(
invert,
);

write!(printer.stdout(), "{tree}")?;
print!("{tree}");

Ok(ExitStatus::Success)
}
74 changes: 74 additions & 0 deletions crates/uv/tests/it/pip_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,77 @@ Version: 0.1-bulbasaur

Ok(())
}

#[test]
fn list_ignores_quiet_flag_format_freeze() {
let context = TestContext::new("3.12");

// Install the editable package.
uv_snapshot!(context.filters(), context
.pip_install()
.arg("-e")
.arg(context.workspace_root.join("scripts/packages/poetry_editable")), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 4 packages in [TIME]
Prepared 4 packages in [TIME]
Installed 4 packages in [TIME]
+ anyio==4.3.0
+ idna==3.6
+ poetry-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/poetry_editable)
+ sniffio==1.3.1
"###
);

let filters = context
.filters()
.into_iter()
.chain(vec![(r"\-\-\-\-\-\-+.*", "[UNDERLINE]"), (" +", " ")])
.collect::<Vec<_>>();

uv_snapshot!(filters, context.pip_list()
.arg("--format=freeze")
.arg("--quiet"), @r###"
success: true
exit_code: 0
----- stdout -----
anyio==4.3.0
idna==3.6
poetry-editable==0.1.0
sniffio==1.3.1

----- stderr -----
"###
);

uv_snapshot!(filters, context.pip_list()
.arg("--format=freeze")
.arg("--editable")
.arg("--quiet"), @r###"
success: true
exit_code: 0
----- stdout -----
poetry-editable==0.1.0

----- stderr -----
"###
);

uv_snapshot!(filters, context.pip_list()
.arg("--format=freeze")
.arg("--exclude-editable")
.arg("--quiet"), @r###"
success: true
exit_code: 0
----- stdout -----
anyio==4.3.0
idna==3.6
sniffio==1.3.1

----- stderr -----
"###
);
}
39 changes: 39 additions & 0 deletions crates/uv/tests/it/pip_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,3 +1744,42 @@ fn show_version_specifiers_with_package() {
"###
);
}

#[test]
fn print_output_even_with_quite_flag() {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("requests==2.31.0").unwrap();

uv_snapshot!(context
.pip_install()
.arg("-r")
.arg("requirements.txt")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 5 packages in [TIME]
Prepared 5 packages in [TIME]
Installed 5 packages in [TIME]
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ requests==2.31.0
+ urllib3==2.2.1
"###
);

context.assert_command("import requests").success();
uv_snapshot!(context.filters(), context.pip_tree().arg("--quiet"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
"###
);
}
Loading