Skip to content

Commit 897508a

Browse files
Avoid subsequent index hint when no versions are available on the first index (#9332)
As reported in #9331, this hint is misleading. --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent e52cd5c commit 897508a

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

crates/uv-resolver/src/pubgrub/report.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -895,21 +895,29 @@ impl PubGrubReportFormatter<'_> {
895895
// Add hints due to the package being available on an index, but not at the correct version,
896896
// with subsequent indexes that were _not_ queried.
897897
if matches!(selector.index_strategy(), IndexStrategy::FirstIndex) {
898-
if let Some(found_index) = available_indexes.get(name).and_then(BTreeSet::first) {
899-
// Determine whether the index is the last-available index. If not, then some
900-
// indexes were not queried, and could contain a compatible version.
901-
if let Some(next_index) = index_locations
902-
.indexes()
903-
.map(Index::url)
904-
.skip_while(|url| *url != found_index)
905-
.nth(1)
906-
{
907-
hints.insert(PubGrubHint::UncheckedIndex {
908-
name: name.clone(),
909-
range: set.clone(),
910-
found_index: found_index.clone(),
911-
next_index: next_index.clone(),
912-
});
898+
// Do not include the hint if the set is "all versions". This is an unusual but valid
899+
// case in which a package returns a 200 response, but without any versions or
900+
// distributions for the package.
901+
if !set
902+
.iter()
903+
.all(|range| matches!(range, (Bound::Unbounded, Bound::Unbounded)))
904+
{
905+
if let Some(found_index) = available_indexes.get(name).and_then(BTreeSet::first) {
906+
// Determine whether the index is the last-available index. If not, then some
907+
// indexes were not queried, and could contain a compatible version.
908+
if let Some(next_index) = index_locations
909+
.indexes()
910+
.map(Index::url)
911+
.skip_while(|url| *url != found_index)
912+
.nth(1)
913+
{
914+
hints.insert(PubGrubHint::UncheckedIndex {
915+
name: name.clone(),
916+
range: set.clone(),
917+
found_index: found_index.clone(),
918+
next_index: next_index.clone(),
919+
});
920+
}
913921
}
914922
}
915923
}

crates/uv/tests/it/pip_compile.rs

+31
Original file line numberDiff line numberDiff line change
@@ -12439,6 +12439,37 @@ fn compile_index_url_first_match_marker() -> Result<()> {
1243912439
Ok(())
1244012440
}
1244112441

12442+
/// Install a package via `--extra-index-url`.
12443+
///
12444+
/// If the package "exists" on the "extra" index, but without any versions, the resolution
12445+
/// should fail by default (even though a compatible version exists on the "primary" index).
12446+
#[test]
12447+
fn compile_index_url_first_match_all_versions() -> Result<()> {
12448+
let context = TestContext::new("3.12");
12449+
12450+
let requirements_in = context.temp_dir.child("requirements.in");
12451+
requirements_in.write_str("pandas")?;
12452+
12453+
uv_snapshot!(context.filters(), context.pip_compile()
12454+
.arg("--index-url")
12455+
.arg("https://pypi.org/simple")
12456+
.arg("--extra-index-url")
12457+
.arg("https://test.pypi.org/simple")
12458+
.arg("requirements.in")
12459+
.arg("--no-deps"), @r###"
12460+
success: false
12461+
exit_code: 1
12462+
----- stdout -----
12463+
12464+
----- stderr -----
12465+
× No solution found when resolving dependencies:
12466+
╰─▶ Because there are no versions of pandas and you require pandas, we can conclude that your requirements are unsatisfiable.
12467+
"###
12468+
);
12469+
12470+
Ok(())
12471+
}
12472+
1244212473
/// Install a package via `--extra-index-url`.
1244312474
///
1244412475
/// If the package exists exist on the "extra" index, but at an incompatible version, the

0 commit comments

Comments
 (0)