Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/uv-distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,11 @@ impl<'a> IndexUrls {
/// If `no_index` was enabled, then this always returns an empty
/// iterator.
pub fn indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
let mut seen = FxHashSet::default();
self.implicit_indexes()
.chain(self.default_index())
.filter(|index| !index.explicit)
.filter(move |index| seen.insert(index.raw_url())) // Filter out redundant raw URLs
}

/// Return an iterator over all user-defined [`Index`] entries in order.
Expand Down
37 changes: 37 additions & 0 deletions crates/uv/tests/it/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,43 @@ fn install_extra_index_url_has_priority() {
context.assert_command("import flask").failure();
}

/// Ensure that the index is fetched only once when duplicate indices are specified
#[tokio::test]
async fn install_deduplicated_indices() {
let context = TestContext::new("3.12");

let redirect_server = MockServer::start().await;

Mock::given(method("GET"))
.respond_with(
ResponseTemplate::new(302).insert_header("Location", "https://pypi.org/simple/sniffio"),
)
.expect(1)
.mount(&redirect_server)
.await;

uv_snapshot!(context
.pip_install()
.arg("sniffio") // Use a zero-dependency package
.arg("--index")
.arg(redirect_server.uri())
.arg("--default-index")
.arg(redirect_server.uri())
.arg("--index-strategy")
.arg("unsafe-first-match"), // Anything but "first-index"
@r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ sniffio==1.3.1
");
}

/// Install a package from a public GitHub repository
#[test]
#[cfg(feature = "git")]
Expand Down
Loading