diff --git a/crates/uv/src/commands/pip/compile.rs b/crates/uv/src/commands/pip/compile.rs index 8f0d2493d1a..2623f812314 100644 --- a/crates/uv/src/commands/pip/compile.rs +++ b/crates/uv/src/commands/pip/compile.rs @@ -777,7 +777,7 @@ pub(crate) async fn pip_compile( .into_iter() .filter(|name| resolution.contains(name)) .collect::>(); - if !excluded.is_empty() { + if include_annotations && !excluded.is_empty() { writeln!(writer)?; writeln!( writer, diff --git a/crates/uv/tests/pip_compile/pip_compile.rs b/crates/uv/tests/pip_compile/pip_compile.rs index a0c480179eb..6564ba3698a 100644 --- a/crates/uv/tests/pip_compile/pip_compile.rs +++ b/crates/uv/tests/pip_compile/pip_compile.rs @@ -10825,6 +10825,38 @@ fn unsafe_package() -> Result<()> { Ok(()) } +/// Exclude the unsafe-package footer when annotations are disabled. +#[test] +fn unsafe_package_no_annotate() -> Result<()> { + let context = uv_test::test_context!("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("flask")?; + + uv_snapshot!(context.filters(), context.pip_compile() + .arg("requirements.in") + .arg("--unsafe-package") + .arg("jinja2") + .arg("--no-annotate"), @" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] requirements.in --unsafe-package jinja2 --no-annotate + blinker==1.7.0 + click==8.1.7 + flask==3.0.2 + itsdangerous==2.1.2 + markupsafe==2.1.5 + werkzeug==3.0.1 + + ----- stderr ----- + Resolved 7 packages in [TIME] + " + ); + + Ok(()) +} + /// Resolve a package with a strict upper bound, allowing pre-releases. Per PEP 440, pre-releases /// that match the bound (e.g., `2.0.0rc1`) should be _not_ allowed. #[test]