Skip to content

Commit

Permalink
Avoid extra-only filtering for constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 6, 2024
1 parent 39f8978 commit 60270e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 1 addition & 3 deletions crates/uv-resolver/src/pubgrub/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
38 changes: 38 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 60270e6

Please sign in to comment.