From e49d61db1fb808819fdf86ddc5bee45fcab047f7 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 22 Jul 2025 08:21:54 -0500 Subject: [PATCH] Emit JSON output with `--quiet` (#14810) --- crates/uv/src/commands/project/sync.rs | 4 +-- crates/uv/tests/it/sync.rs | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/crates/uv/src/commands/project/sync.rs b/crates/uv/src/commands/project/sync.rs index adf3b61f2..cbce0082a 100644 --- a/crates/uv/src/commands/project/sync.rs +++ b/crates/uv/src/commands/project/sync.rs @@ -273,7 +273,7 @@ pub(crate) async fn sync( dry_run: dry_run.enabled(), }; if let Some(output) = report.format(output_format) { - writeln!(printer.stdout(), "{output}")?; + writeln!(printer.stdout_important(), "{output}")?; } return Ok(ExitStatus::Success); } @@ -363,7 +363,7 @@ pub(crate) async fn sync( }; if let Some(output) = report.format(output_format) { - writeln!(printer.stdout(), "{output}")?; + writeln!(printer.stdout_important(), "{output}")?; } // Identify the installation target. diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 4f2853e61..5ee22eed6 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -432,6 +432,46 @@ fn sync_json() -> Result<()> { The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`. "); + // Test that JSON output is shown even with --quiet flag + uv_snapshot!(context.filters(), context.sync() + .arg("--quiet") + .arg("--frozen") + .arg("--output-format").arg("json"), @r#" + success: true + exit_code: 0 + ----- stdout ----- + { + "schema": { + "version": "preview" + }, + "target": "project", + "project": { + "path": "[TEMP_DIR]/", + "workspace": { + "path": "[TEMP_DIR]/" + } + }, + "sync": { + "environment": { + "path": "[VENV]/", + "python": { + "path": "[VENV]/[BIN]/[PYTHON]", + "version": "3.12.[X]", + "implementation": "cpython" + } + }, + "action": "check" + }, + "lock": { + "path": "[TEMP_DIR]/uv.lock", + "action": "use" + }, + "dry_run": false + } + + ----- stderr ----- + "#); + Ok(()) }