diff --git a/crates/uv-distribution-types/src/index_url.rs b/crates/uv-distribution-types/src/index_url.rs index 3973174b7deb..cd075331e4cb 100644 --- a/crates/uv-distribution-types/src/index_url.rs +++ b/crates/uv-distribution-types/src/index_url.rs @@ -283,6 +283,22 @@ impl<'a> IndexLocations { .filter(|index| !index.explicit) } + /// Return an iterator over all simple [`Index`] entries in order. + /// + /// If `no_index` was enabled, then this always returns an empty iterator. + pub fn simple_indexes(&'a self) -> impl Iterator + 'a { + if self.no_index { + Either::Left(std::iter::empty()) + } else { + let mut seen = FxHashSet::default(); + Either::Right( + self.indexes.iter().filter(move |index| { + index.name.as_ref().map_or(true, |name| seen.insert(name)) + }), + ) + } + } + /// Return an iterator over the [`FlatIndexLocation`] entries. pub fn flat_indexes(&'a self) -> impl Iterator + 'a { self.flat_index.iter() diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index 0ac73dc4f301..9c8d87466c99 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -1218,7 +1218,7 @@ async fn run(mut cli: Cli) -> Result { let (publish_url, check_url) = if let Some(index_name) = index { debug!("Publishing with index {index_name}"); let index = index_locations - .indexes() + .simple_indexes() .find(|index| { index .name @@ -1227,7 +1227,7 @@ async fn run(mut cli: Cli) -> Result { }) .with_context(|| { let mut index_names: Vec = index_locations - .indexes() + .simple_indexes() .filter_map(|index| index.name.as_ref()) .map(ToString::to_string) .collect(); diff --git a/crates/uv/tests/it/publish.rs b/crates/uv/tests/it/publish.rs index 1cd40e15c80f..b49b0a81b930 100644 --- a/crates/uv/tests/it/publish.rs +++ b/crates/uv/tests/it/publish.rs @@ -337,6 +337,7 @@ fn invalid_index() { version = "0.1.0" [[tool.uv.index]] + explicit = true name = "foo" url = "https://example.com"