Skip to content

Commit e4736ef

Browse files
committed
Fix bug in terms when collapsing unavailable versions in resolver errors
1 parent 5903ce5 commit e4736ef

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

crates/uv-resolver/src/error.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::{BTreeMap, BTreeSet, Bound};
22
use std::fmt::Formatter;
3+
use std::str::FromStr;
34
use std::sync::Arc;
45

56
use indexmap::IndexSet;
@@ -673,13 +674,20 @@ fn collapse_unavailable_versions(
673674
// And the package and reason are the same...
674675
if package == other_package && reason == other_reason {
675676
// Collapse both into a new node, with a union of their ranges
677+
let versions = other_versions.union(&versions);
678+
let mut terms = terms.clone();
679+
if let Some(term) = terms.get_mut(package) {
680+
if let Term::Positive(range) = term {
681+
*range = versions.clone();
682+
}
683+
}
676684
*tree = DerivationTree::Derived(Derived {
677-
terms: terms.clone(),
685+
terms: terms,
678686
shared_id: *shared_id,
679687
cause1: cause1.clone(),
680688
cause2: Arc::new(DerivationTree::External(External::Custom(
681689
package.clone(),
682-
versions.union(other_versions),
690+
versions,
683691
reason.clone(),
684692
))),
685693
});
@@ -696,12 +704,27 @@ fn collapse_unavailable_versions(
696704
// And the package and reason are the same...
697705
if package == other_package && reason == other_reason {
698706
// Collapse both into a new node, with a union of their ranges
707+
let versions = other_versions.union(&versions);
708+
let mut terms = terms.clone();
709+
if let Some(term) = terms.get_mut(package) {
710+
if let Term::Positive(range) = term {
711+
*range = versions.clone();
712+
if let Some(version) = versions.as_singleton() {
713+
let upper_bound: Ranges<Version> =
714+
Ranges::from_range_bounds((
715+
Bound::Unbounded,
716+
Bound::Included(version.clone()),
717+
));
718+
*range = range.intersection(&upper_bound);
719+
}
720+
}
721+
}
699722
*tree = DerivationTree::Derived(Derived {
700-
terms: terms.clone(),
723+
terms: terms,
701724
shared_id: *shared_id,
702725
cause1: Arc::new(DerivationTree::External(External::Custom(
703726
package.clone(),
704-
versions.union(other_versions),
727+
versions,
705728
reason.clone(),
706729
))),
707730
cause2: cause2.clone(),

crates/uv/tests/it/cache_prune.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ fn prune_unzipped() -> Result<()> {
263263
and all of:
264264
iniconfig<=0.1
265265
iniconfig>=1.0.0
266-
need to be downloaded from a registry, we can conclude that iniconfig<1.0.0 cannot be used.
266+
need to be downloaded from a registry, we can conclude that all of:
267+
iniconfig<=0.1
268+
iniconfig>=1.0.0
269+
cannot be used.
267270
And because you require iniconfig, we can conclude that your requirements are unsatisfiable.
268271
269272
hint: Pre-releases are available for `iniconfig` in the requested range (e.g., 0.2.dev0), but pre-releases weren't enabled (try: `--prerelease=allow`)

crates/uv/tests/it/pip_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13796,7 +13796,7 @@ fn invalid_platform() -> Result<()> {
1379613796
open3d==0.16.1
1379713797
open3d==0.17.0
1379813798
open3d==0.18.0
13799-
and open3d<=0.15.2 has no wheels with a matching Python ABI tag, we can conclude that open3d<0.9.0.0 cannot be used.
13799+
and open3d<=0.15.2 has no wheels with a matching Python ABI tag, we can conclude that open3d<=0.15.2 cannot be used.
1380013800
And because open3d>=0.16.0 has no wheels with a matching platform tag and you require open3d, we can conclude that your requirements are unsatisfiable.
1380113801
"###);
1380213802

crates/uv/tests/it/pip_install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,11 +2182,11 @@ fn install_only_binary_all_and_no_binary_all() {
21822182
anyio>=3.7.0,<=3.7.1
21832183
anyio>=4.0.0
21842184
have no usable wheels and building from source is disabled, we can conclude that all of:
2185-
anyio<1.1.0
2186-
anyio>1.4.0,<2.0.0
2187-
anyio>2.2.0,<3.0.0
2188-
anyio>3.6.2,<3.7.0
2189-
anyio>3.7.1,<4.0.0
2185+
anyio>=1.0.0,<=1.4.0
2186+
anyio>=2.0.0,<=2.2.0
2187+
anyio>=3.0.0,<=3.6.2
2188+
anyio>=3.7.0,<=3.7.1
2189+
anyio>=4.0.0
21902190
cannot be used.
21912191
And because you require anyio, we can conclude that your requirements are unsatisfiable.
21922192

crates/uv/tests/it/tool_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn tool_list_show_version_specifiers() {
276276

277277
uv_snapshot!(context.filters(), context.tool_list().arg("--show-version-specifiers")
278278
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
279-
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r#"
279+
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
280280
success: true
281281
exit_code: 0
282282
----- stdout -----
@@ -287,12 +287,12 @@ fn tool_list_show_version_specifiers() {
287287
- flask
288288
289289
----- stderr -----
290-
"#);
290+
"###);
291291

292292
// with paths
293293
uv_snapshot!(context.filters(), context.tool_list().arg("--show-version-specifiers").arg("--show-paths")
294294
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
295-
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r#"
295+
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
296296
success: true
297297
exit_code: 0
298298
----- stdout -----
@@ -303,5 +303,5 @@ fn tool_list_show_version_specifiers() {
303303
- flask ([TEMP_DIR]/bin/flask)
304304
305305
----- stderr -----
306-
"#);
306+
"###);
307307
}

0 commit comments

Comments
 (0)