Skip to content

Commit

Permalink
Avoid dropping pip-sync requirements with markers
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 5, 2024
1 parent b0d1fc8 commit 5e0312f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,21 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.wait_blocking(&version_id)
.ok_or(ResolveError::Unregistered)?;

return Ok(Dependencies::Available(Vec::default()));
// If a package has a marker, add a dependency from it to the
// same package without markers.
return Ok(Dependencies::Available(if marker.is_some() {
vec![(
PubGrubPackage::from(PubGrubPackageInner::Package {
name: name.clone(),
extra: extra.clone(),
marker: None,
url: url.clone(),
}),
Range::singleton(version.clone()),
)]
} else {
vec![]
}));
}

// Determine the distribution to lookup.
Expand Down
25 changes: 25 additions & 0 deletions crates/uv/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5164,3 +5164,28 @@ fn target_no_build_isolation() -> Result<()> {

Ok(())
}

/// Ensure that we install packages with markers on them.
#[test]
fn preserve_markers() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("anyio ; python_version > '3.7'")?;

uv_snapshot!(sync_without_exclude_newer(&context)
.arg("requirements.txt"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ anyio==4.4.0
"###
);

Ok(())
}

0 comments on commit 5e0312f

Please sign in to comment.