Skip to content

Commit 823ee8f

Browse files
Modify pip list and tree to print to stdout regardless of the --quiet flag (#8392)
## Summary The desired behavior for `uv tree` and `uv pip list` with `-q | --quiet` flag is #8379 (comment) to still produce output. This is implemented here. Closes #8379 ## Test Plan Use `uv tree -q` or `uv pip list -q` on any uv project setup and expect the corresponding output. Added tests for that as well. --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent 6ff674f commit 823ee8f

File tree

4 files changed

+121
-11
lines changed

4 files changed

+121
-11
lines changed

crates/uv/src/commands/pip/list.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::cmp::max;
22
use std::fmt::Write;
33

4+
use anstream::println;
45
use anyhow::Result;
56
use itertools::Itertools;
67
use owo_colors::OwoColorize;
@@ -56,7 +57,7 @@ pub(crate) fn pip_list(
5657
ListFormat::Json => {
5758
let rows = results.iter().copied().map(Entry::from).collect_vec();
5859
let output = serde_json::to_string(&rows)?;
59-
writeln!(printer.stdout(), "{output}")?;
60+
println!("{output}");
6061
}
6162
ListFormat::Columns if results.is_empty() => {}
6263
ListFormat::Columns => {
@@ -97,18 +98,13 @@ pub(crate) fn pip_list(
9798
}
9899

99100
for elems in MultiZip(columns.iter().map(Column::fmt).collect_vec()) {
100-
writeln!(printer.stdout(), "{}", elems.join(" ").trim_end())?;
101+
println!("{}", elems.join(" ").trim_end());
101102
}
102103
}
103104
ListFormat::Freeze if results.is_empty() => {}
104105
ListFormat::Freeze => {
105106
for dist in &results {
106-
writeln!(
107-
printer.stdout(),
108-
"{}=={}",
109-
dist.name().bold(),
110-
dist.version()
111-
)?;
107+
println!("{}=={}", dist.name().bold(), dist.version());
112108
}
113109
}
114110
}

crates/uv/src/commands/project/tree.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use anyhow::Result;
2-
use std::fmt::Write;
31
use std::path::Path;
42

3+
use anstream::print;
4+
use anyhow::Result;
5+
56
use uv_cache::Cache;
67
use uv_client::Connectivity;
78
use uv_configuration::{Concurrency, DevMode, LowerBound, TargetTriple};
@@ -100,7 +101,7 @@ pub(crate) async fn tree(
100101
invert,
101102
);
102103

103-
write!(printer.stdout(), "{tree}")?;
104+
print!("{tree}");
104105

105106
Ok(ExitStatus::Success)
106107
}

crates/uv/tests/it/pip_list.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,77 @@ Version: 0.1-bulbasaur
525525

526526
Ok(())
527527
}
528+
529+
#[test]
530+
fn list_ignores_quiet_flag_format_freeze() {
531+
let context = TestContext::new("3.12");
532+
533+
// Install the editable package.
534+
uv_snapshot!(context.filters(), context
535+
.pip_install()
536+
.arg("-e")
537+
.arg(context.workspace_root.join("scripts/packages/poetry_editable")), @r###"
538+
success: true
539+
exit_code: 0
540+
----- stdout -----
541+
542+
----- stderr -----
543+
Resolved 4 packages in [TIME]
544+
Prepared 4 packages in [TIME]
545+
Installed 4 packages in [TIME]
546+
+ anyio==4.3.0
547+
+ idna==3.6
548+
+ poetry-editable==0.1.0 (from file://[WORKSPACE]/scripts/packages/poetry_editable)
549+
+ sniffio==1.3.1
550+
"###
551+
);
552+
553+
let filters = context
554+
.filters()
555+
.into_iter()
556+
.chain(vec![(r"\-\-\-\-\-\-+.*", "[UNDERLINE]"), (" +", " ")])
557+
.collect::<Vec<_>>();
558+
559+
uv_snapshot!(filters, context.pip_list()
560+
.arg("--format=freeze")
561+
.arg("--quiet"), @r###"
562+
success: true
563+
exit_code: 0
564+
----- stdout -----
565+
anyio==4.3.0
566+
idna==3.6
567+
poetry-editable==0.1.0
568+
sniffio==1.3.1
569+
570+
----- stderr -----
571+
"###
572+
);
573+
574+
uv_snapshot!(filters, context.pip_list()
575+
.arg("--format=freeze")
576+
.arg("--editable")
577+
.arg("--quiet"), @r###"
578+
success: true
579+
exit_code: 0
580+
----- stdout -----
581+
poetry-editable==0.1.0
582+
583+
----- stderr -----
584+
"###
585+
);
586+
587+
uv_snapshot!(filters, context.pip_list()
588+
.arg("--format=freeze")
589+
.arg("--exclude-editable")
590+
.arg("--quiet"), @r###"
591+
success: true
592+
exit_code: 0
593+
----- stdout -----
594+
anyio==4.3.0
595+
idna==3.6
596+
sniffio==1.3.1
597+
598+
----- stderr -----
599+
"###
600+
);
601+
}

crates/uv/tests/it/pip_tree.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,3 +1744,42 @@ fn show_version_specifiers_with_package() {
17441744
"###
17451745
);
17461746
}
1747+
1748+
#[test]
1749+
fn print_output_even_with_quite_flag() {
1750+
let context = TestContext::new("3.12");
1751+
1752+
let requirements_txt = context.temp_dir.child("requirements.txt");
1753+
requirements_txt.write_str("requests==2.31.0").unwrap();
1754+
1755+
uv_snapshot!(context
1756+
.pip_install()
1757+
.arg("-r")
1758+
.arg("requirements.txt")
1759+
.arg("--strict"), @r###"
1760+
success: true
1761+
exit_code: 0
1762+
----- stdout -----
1763+
1764+
----- stderr -----
1765+
Resolved 5 packages in [TIME]
1766+
Prepared 5 packages in [TIME]
1767+
Installed 5 packages in [TIME]
1768+
+ certifi==2024.2.2
1769+
+ charset-normalizer==3.3.2
1770+
+ idna==3.6
1771+
+ requests==2.31.0
1772+
+ urllib3==2.2.1
1773+
"###
1774+
);
1775+
1776+
context.assert_command("import requests").success();
1777+
uv_snapshot!(context.filters(), context.pip_tree().arg("--quiet"), @r###"
1778+
success: true
1779+
exit_code: 0
1780+
----- stdout -----
1781+
1782+
----- stderr -----
1783+
"###
1784+
);
1785+
}

0 commit comments

Comments
 (0)