Show package list with `pip freeze --quiet` (#16491)

## Summary

Closes https://github.com/astral-sh/uv/issues/16178.
This commit is contained in:
Charlie Marsh 2025-10-29 11:00:00 -04:00 committed by GitHub
parent 61c67bebcb
commit a759612bc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 5 deletions

View File

@ -83,7 +83,7 @@ pub(crate) fn pip_freeze(
}
})
.dedup()
.try_for_each(|dist| writeln!(printer.stdout(), "{dist}"))?;
.try_for_each(|dist| writeln!(printer.stdout_important(), "{dist}"))?;
// Validate that the environment is consistent.
if strict {

View File

@ -1,7 +1,6 @@
use std::cmp::max;
use std::fmt::Write;
use anstream::println;
use anyhow::Result;
use futures::StreamExt;
use itertools::Itertools;
@ -181,7 +180,7 @@ pub(crate) async fn pip_list(
})
.collect_vec();
let output = serde_json::to_string(&rows)?;
println!("{output}");
writeln!(printer.stdout_important(), "{output}")?;
}
ListFormat::Columns if results.is_empty() => {}
ListFormat::Columns => {
@ -255,13 +254,18 @@ pub(crate) async fn pip_list(
}
for elems in MultiZip(columns.iter().map(Column::fmt).collect_vec()) {
println!("{}", elems.join(" ").trim_end());
writeln!(printer.stdout_important(), "{}", elems.join(" ").trim_end())?;
}
}
ListFormat::Freeze if results.is_empty() => {}
ListFormat::Freeze => {
for dist in &results {
println!("{}=={}", dist.name().bold(), dist.version());
writeln!(
printer.stdout_important(),
"{}=={}",
dist.name().bold(),
dist.version()
)?;
}
}
}

View File

@ -453,3 +453,32 @@ fn freeze_nonexistent_path() {
----- stderr -----
");
}
#[test]
fn freeze_with_quiet_flag() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;
// Run `pip sync`.
context
.pip_sync()
.arg(requirements_txt.path())
.assert()
.success();
// Run `pip freeze` with `--quiet` flag.
uv_snapshot!(context.pip_freeze().arg("--quiet"), @r###"
success: true
exit_code: 0
----- stdout -----
markupsafe==2.1.3
tomli==2.0.1
----- stderr -----
"###
);
Ok(())
}