Skip to content

Commit 4b8cc3e

Browse files
authored
Include explicit indexes in publish index choice (#9932)
For publishing, we want to allow all simple `[[tool.uv.index]]` entries, whether they are explicit or not. We don't allow flat indexes here, assuming that an index you can upload to has a simple index URL (and generally doesn't have a flat index URL, at least I don't know any case that has). The `no_index` branch isn't used atm, but I left it in case the method gathers more users. Fixes #9919
1 parent 431ddc1 commit 4b8cc3e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

crates/uv-distribution-types/src/index_url.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ impl<'a> IndexLocations {
283283
.filter(|index| !index.explicit)
284284
}
285285

286+
/// Return an iterator over all simple [`Index`] entries in order.
287+
///
288+
/// If `no_index` was enabled, then this always returns an empty iterator.
289+
pub fn simple_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
290+
if self.no_index {
291+
Either::Left(std::iter::empty())
292+
} else {
293+
let mut seen = FxHashSet::default();
294+
Either::Right(
295+
self.indexes.iter().filter(move |index| {
296+
index.name.as_ref().map_or(true, |name| seen.insert(name))
297+
}),
298+
)
299+
}
300+
}
301+
286302
/// Return an iterator over the [`FlatIndexLocation`] entries.
287303
pub fn flat_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
288304
self.flat_index.iter()

crates/uv/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
12181218
let (publish_url, check_url) = if let Some(index_name) = index {
12191219
debug!("Publishing with index {index_name}");
12201220
let index = index_locations
1221-
.indexes()
1221+
.simple_indexes()
12221222
.find(|index| {
12231223
index
12241224
.name
@@ -1227,7 +1227,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
12271227
})
12281228
.with_context(|| {
12291229
let mut index_names: Vec<String> = index_locations
1230-
.indexes()
1230+
.simple_indexes()
12311231
.filter_map(|index| index.name.as_ref())
12321232
.map(ToString::to_string)
12331233
.collect();

crates/uv/tests/it/publish.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ fn invalid_index() {
337337
version = "0.1.0"
338338
339339
[[tool.uv.index]]
340+
explicit = true
340341
name = "foo"
341342
url = "https://example.com"
342343

0 commit comments

Comments
 (0)