mirror of https://github.com/astral-sh/uv
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 https://github.com/astral-sh/uv/issues/8379#issuecomment-2425093709 to still produce output. This is implemented here. Closes https://github.com/astral-sh/uv/issues/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 <charlie.r.marsh@gmail.com>
This commit is contained in:
parent
6ff674f5bf
commit
823ee8fcb0
|
|
@ -1,6 +1,7 @@
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
use anstream::println;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
|
|
@ -56,7 +57,7 @@ pub(crate) fn pip_list(
|
||||||
ListFormat::Json => {
|
ListFormat::Json => {
|
||||||
let rows = results.iter().copied().map(Entry::from).collect_vec();
|
let rows = results.iter().copied().map(Entry::from).collect_vec();
|
||||||
let output = serde_json::to_string(&rows)?;
|
let output = serde_json::to_string(&rows)?;
|
||||||
writeln!(printer.stdout(), "{output}")?;
|
println!("{output}");
|
||||||
}
|
}
|
||||||
ListFormat::Columns if results.is_empty() => {}
|
ListFormat::Columns if results.is_empty() => {}
|
||||||
ListFormat::Columns => {
|
ListFormat::Columns => {
|
||||||
|
|
@ -97,18 +98,13 @@ pub(crate) fn pip_list(
|
||||||
}
|
}
|
||||||
|
|
||||||
for elems in MultiZip(columns.iter().map(Column::fmt).collect_vec()) {
|
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 if results.is_empty() => {}
|
||||||
ListFormat::Freeze => {
|
ListFormat::Freeze => {
|
||||||
for dist in &results {
|
for dist in &results {
|
||||||
writeln!(
|
println!("{}=={}", dist.name().bold(), dist.version());
|
||||||
printer.stdout(),
|
|
||||||
"{}=={}",
|
|
||||||
dist.name().bold(),
|
|
||||||
dist.version()
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use anyhow::Result;
|
|
||||||
use std::fmt::Write;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use anstream::print;
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::Connectivity;
|
use uv_client::Connectivity;
|
||||||
use uv_configuration::{Concurrency, DevMode, LowerBound, TargetTriple};
|
use uv_configuration::{Concurrency, DevMode, LowerBound, TargetTriple};
|
||||||
|
|
@ -100,7 +101,7 @@ pub(crate) async fn tree(
|
||||||
invert,
|
invert,
|
||||||
);
|
);
|
||||||
|
|
||||||
write!(printer.stdout(), "{tree}")?;
|
print!("{tree}");
|
||||||
|
|
||||||
Ok(ExitStatus::Success)
|
Ok(ExitStatus::Success)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -525,3 +525,77 @@ Version: 0.1-bulbasaur
|
||||||
|
|
||||||
Ok(())
|
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 -----
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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…
Reference in New Issue