Skip to content

Commit

Permalink
make universal resolver fork only when markers are disjoint (#4135)
Browse files Browse the repository at this point in the history
The basic idea here is to make it so forking can only ever result in a
resolution that, for a particular marker environment, will only install
at most one version of a package. We can guarantee this by ensuring we
only fork on conflicting dependency specifications only when their
corresponding markers are completely disjoint. If they aren't, then
resolution _must_ find a single version of the package in the
intersection of the two dependency specifications.

A test for this case has been added to packse here:
astral-sh/packse#182. Previously, that test
would result in a resolution with two different unconditional versions
of the same package. With this change, resolution fails (as it should).

A commit-by-commit review should be helpful here, since the first commit
is a refactor to make the second commit a bit more digestible.
  • Loading branch information
BurntSushi authored Jun 7, 2024
1 parent 0db1bf4 commit c46fa74
Show file tree
Hide file tree
Showing 7 changed files with 484 additions and 204 deletions.
428 changes: 322 additions & 106 deletions crates/uv-resolver/src/resolver/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub static EXCLUDE_NEWER: &str = "2024-03-25T00:00:00Z";
/// Using a find links url allows using `--index-url` instead of `--extra-index-url` in tests
/// to prevent dependency confusion attacks against our test suite.
pub const BUILD_VENDOR_LINKS_URL: &str =
"https://raw.githubusercontent.com/astral-sh/packse/0.3.17/vendor/links.html";
"https://raw.githubusercontent.com/astral-sh/packse/0.3.18/vendor/links.html";

#[doc(hidden)] // Macro and test context only, don't use directly.
pub const INSTA_FILTERS: &[(&str, &str)] = &[
Expand Down
242 changes: 153 additions & 89 deletions crates/uv/tests/lock_scenarios.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/uv/tests/pip_compile_scenarios.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! DO NOT EDIT
//!
//! Generated with `./scripts/sync_scenarios.sh`
//! Scenarios from <https://github.com/astral-sh/packse/tree/0.3.17/scenarios>
//! Scenarios from <https://github.com/astral-sh/packse/tree/0.3.18/scenarios>
//!
#![cfg(all(feature = "python", feature = "pypi", unix))]

Expand All @@ -27,9 +27,9 @@ fn command(context: &TestContext, python_versions: &[&str]) -> Command {
.arg("compile")
.arg("requirements.in")
.arg("--index-url")
.arg("https://astral-sh.github.io/packse/0.3.17/simple-html/")
.arg("https://astral-sh.github.io/packse/0.3.18/simple-html/")
.arg("--find-links")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.17/vendor/links.html")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.18/vendor/links.html")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/tests/pip_install_scenarios.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! DO NOT EDIT
//!
//! Generated with `./scripts/sync_scenarios.sh`
//! Scenarios from <https://github.com/astral-sh/packse/tree/0.3.17/scenarios>
//! Scenarios from <https://github.com/astral-sh/packse/tree/0.3.18/scenarios>
//!
#![cfg(all(feature = "python", feature = "pypi", unix))]

Expand Down Expand Up @@ -46,9 +46,9 @@ fn command(context: &TestContext) -> Command {
.arg("pip")
.arg("install")
.arg("--index-url")
.arg("https://astral-sh.github.io/packse/0.3.17/simple-html/")
.arg("https://astral-sh.github.io/packse/0.3.18/simple-html/")
.arg("--find-links")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.17/vendor/links.html")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.18/vendor/links.html")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
Expand Down
2 changes: 1 addition & 1 deletion scripts/scenarios/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
chevron-blue
packse>=0.3.17
packse>=0.3.18
2 changes: 1 addition & 1 deletion scripts/scenarios/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ nh3==0.2.17
# via readme-renderer
packaging==24.0
# via hatchling
packse==0.3.17
packse==0.3.18
# via -r scripts/scenarios/requirements.in
pathspec==0.12.1
# via hatchling
Expand Down

0 comments on commit c46fa74

Please sign in to comment.