From c7d7b074084a84cf5bc22e6d387b58b8dffbebf6 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 23 Apr 2024 21:52:41 -0400 Subject: [PATCH] Add test for extra-in-constraint (#3231) ## Summary We have the wrong behavior here, so starting by adding a test for it. --- crates/uv/tests/pip_compile.rs | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 0afe8a6df..228967c27 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -288,6 +288,54 @@ fn compile_constraints_markers() -> Result<()> { Ok(()) } +/// Resolve a package from a `requirements.in` file, with a `constraints.txt` file that uses an +/// extra. The constraint should be enforced, but the extra should _not_ be included in the output +/// (though it currently _is_ included). +#[test] +fn compile_constraint_extra() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("flask")?; + + // Constrain a transitive dependency based on the Python version + let constraints_txt = context.temp_dir.child("constraints.txt"); + constraints_txt.write_str("flask[dotenv]<24.3.0")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--constraint") + .arg("constraints.txt"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --constraint constraints.txt + blinker==1.7.0 + # via flask + click==8.1.7 + # via flask + flask==3.0.2 + itsdangerous==2.1.2 + # via flask + jinja2==3.1.3 + # via flask + markupsafe==2.1.5 + # via + # jinja2 + # werkzeug + python-dotenv==1.0.1 + # via flask + werkzeug==3.0.1 + # via flask + + ----- stderr ----- + Resolved 8 packages in [TIME] + "### + ); + + Ok(()) +} + /// Resolve a package from an optional dependency group in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_extra() -> Result<()> {