Skip to content

Commit

Permalink
Support overlapping local and non-local requirements in forks (#5812)
Browse files Browse the repository at this point in the history
## Summary

This fixes a bug introduced by
#5232. It turns out that the
`universal_disjoint_base_or_local_requirement` test does not actually do
what it was meant to because of the incorrect python requirement. With a
valid python requirement, it fails on `main`. The problem is that we try
to exclude the original base version from the range of allowed versions
to try and prefer local versions. However, in the test, there is a
branch that depends on the non-local version, with no applicable local
in its fork. We should remove this exclusion as prioritization is
handled by the candidate resolver.
  • Loading branch information
ibraheemdev authored Aug 6, 2024
1 parent 089f50a commit e651e67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
5 changes: 0 additions & 5 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,11 +2117,6 @@ impl ForkState {
if let Some(specifier) = specifier {
let locals = locals.get(name, &self.markers);

// Prioritize local versions over the original version range.
if !locals.is_empty() {
*version = Range::empty();
}

// It's possible that there are multiple matching local versions requested with
// different marker expressions. All of these are potentially compatible until we
// narrow to a specific fork.
Expand Down
40 changes: 22 additions & 18 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7170,19 +7170,19 @@ fn universal_disjoint_local_requirement() -> Result<()> {
/// expressions, we should fork the root requirement.
#[test]
fn universal_disjoint_base_or_local_requirement() -> Result<()> {
let context = TestContext::new("3.12");
let context = TestContext::new("3.10");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "example"
version = "0.0.0"
dependencies = [
"torch==2.0.0; python_version < '3.10'",
"torch==2.0.0+cu118 ; python_version >= '3.10' and python_version <= '3.12'",
"torch==2.0.0; python_version < '3.11'",
"torch==2.0.0+cu118 ; python_version >= '3.11' and python_version <= '3.12'",
"torch==2.0.0+cpu ; python_version > '3.12'"
]
requires-python = ">=3.11"
requires-python = ">=3.10"
"#})?;

let requirements_in = context.temp_dir.child("requirements.in");
Expand All @@ -7203,42 +7203,46 @@ fn universal_disjoint_base_or_local_requirement() -> Result<()> {
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --universal
cmake==3.28.4 ; python_version <= '3.12' and platform_machine == 'x86_64' and platform_system == 'Linux'
cmake==3.28.4 ; python_version <= '3.12' and python_version >= '3.11' and platform_machine == 'x86_64' and platform_system == 'Linux'
# via triton
.
. ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')
# via -r requirements.in
filelock==3.13.1
filelock==3.13.1 ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11') or (python_version <= '3.12' and python_version >= '3.11' and platform_machine == 'x86_64' and platform_system == 'Linux')
# via
# torch
# triton
jinja2==3.1.3
jinja2==3.1.3 ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')
# via torch
lit==18.1.2 ; python_version <= '3.12' and platform_machine == 'x86_64' and platform_system == 'Linux'
lit==18.1.2 ; python_version <= '3.12' and python_version >= '3.11' and platform_machine == 'x86_64' and platform_system == 'Linux'
# via triton
markupsafe==2.1.5
markupsafe==2.1.5 ; (python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')) and (python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11'))
# via jinja2
mpmath==1.3.0
mpmath==1.3.0 ; (python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')) and (python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11'))
# via sympy
networkx==3.2.1
networkx==3.2.1 ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')
# via torch
sympy==1.12
sympy==1.12 ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')
# via torch
torch==2.0.0+cpu
torch==2.0.0 ; python_version < '3.11' or (python_version <= '3.12' and python_version > '3.12' and python_version >= '3.11')
# via
# -r requirements.in
# example
torch==2.0.0+cpu ; python_version > '3.12'
# via
# -r requirements.in
# example
torch==2.0.0+cu118 ; python_version <= '3.12'
torch==2.0.0+cu118 ; python_version <= '3.12' and python_version >= '3.11'
# via
# -r requirements.in
# example
# triton
triton==2.0.0 ; python_version <= '3.12' and platform_machine == 'x86_64' and platform_system == 'Linux'
triton==2.0.0 ; python_version <= '3.12' and python_version >= '3.11' and platform_machine == 'x86_64' and platform_system == 'Linux'
# via torch
typing-extensions==4.10.0
typing-extensions==4.10.0 ; python_version < '3.11' or python_version > '3.12' or (python_version <= '3.12' and python_version >= '3.11')
# via torch
----- stderr -----
Resolved 13 packages in [TIME]
Resolved 14 packages in [TIME]
"###
);

Expand Down

0 comments on commit e651e67

Please sign in to comment.