From 60270e62bc978dcd973d9eb79605d1ec5e04fa12 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 6 Jun 2024 09:44:18 -0400 Subject: [PATCH] Avoid extra-only filtering for constraints --- .../uv-resolver/src/pubgrub/dependencies.rs | 4 +- crates/uv/tests/pip_install.rs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/uv-resolver/src/pubgrub/dependencies.rs b/crates/uv-resolver/src/pubgrub/dependencies.rs index 3f02c3a91a53..454b4ade42d6 100644 --- a/crates/uv-resolver/src/pubgrub/dependencies.rs +++ b/crates/uv-resolver/src/pubgrub/dependencies.rs @@ -97,6 +97,7 @@ fn add_requirements( // If the requirement isn't relevant for the current platform, skip it. match source_extra { Some(source_extra) => { + // Only include requirements that are relevant for the current extra. if requirement.evaluate_markers(env, &[]) { continue; } @@ -167,9 +168,6 @@ fn add_requirements( // If the requirement isn't relevant for the current platform, skip it. match source_extra { Some(source_extra) => { - if constraint.evaluate_markers(env, &[]) { - continue; - } if !constraint.evaluate_markers(env, std::slice::from_ref(source_extra)) { continue; } diff --git a/crates/uv/tests/pip_install.rs b/crates/uv/tests/pip_install.rs index 7b5db3e2a813..1a89e6e0349d 100644 --- a/crates/uv/tests/pip_install.rs +++ b/crates/uv/tests/pip_install.rs @@ -2315,6 +2315,44 @@ fn install_constraints_inline_remote() -> Result<()> { Ok(()) } +/// Constrain a package that's included via an extra. +#[test] +fn install_constraints_extra() -> Result<()> { + let context = TestContext::new("3.12"); + + let requirements_txt = context.temp_dir.child("requirements.txt"); + requirements_txt.write_str("flask[dotenv]")?; + + let constraints_txt = context.temp_dir.child("constraints.txt"); + constraints_txt.write_str("python-dotenv==1.0.0")?; + + uv_snapshot!(context.install() + .arg("-r") + .arg("requirements.txt") + .arg("-c") + .arg("constraints.txt"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 8 packages in [TIME] + Downloaded 8 packages in [TIME] + Installed 8 packages in [TIME] + + blinker==1.7.0 + + click==8.1.7 + + flask==3.0.2 + + itsdangerous==2.1.2 + + jinja2==3.1.3 + + markupsafe==2.1.5 + + python-dotenv==1.0.0 + + werkzeug==3.0.1 + "### + ); + + Ok(()) +} + #[test] fn install_constraints_respects_offline_mode() { let context = TestContext::new("3.12");