mirror of https://github.com/astral-sh/uv
Ignore if default is set
This commit is contained in:
parent
bdfeae7970
commit
e0246b70db
|
|
@ -27,8 +27,9 @@ static DEFAULT_INDEX: LazyLock<Index> = LazyLock::new(|| {
|
||||||
))))
|
))))
|
||||||
});
|
});
|
||||||
|
|
||||||
static VARIANT_URL: LazyLock<DisplaySafeUrl> =
|
static VARIANT_URL: LazyLock<DisplaySafeUrl> = LazyLock::new(|| {
|
||||||
LazyLock::new(|| DisplaySafeUrl::parse("https://variants-index.wheelnext.dev").unwrap());
|
DisplaySafeUrl::parse("https://download.pytorch.org/whl/test/variant").unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
static VARIANT_INDEX: LazyLock<Index> = LazyLock::new(|| {
|
static VARIANT_INDEX: LazyLock<Index> = LazyLock::new(|| {
|
||||||
Index::from_extra_index_url(IndexUrl::Url(Arc::new(VerbatimUrl::from_url(
|
Index::from_extra_index_url(IndexUrl::Url(Arc::new(VerbatimUrl::from_url(
|
||||||
|
|
@ -334,13 +335,24 @@ impl<'a> IndexLocations {
|
||||||
if self.no_index {
|
if self.no_index {
|
||||||
Either::Left(std::iter::empty())
|
Either::Left(std::iter::empty())
|
||||||
} else {
|
} else {
|
||||||
|
// Determine whether the user defined a default index.
|
||||||
|
let mut seen = FxHashSet::default();
|
||||||
|
let has_default = self
|
||||||
|
.indexes
|
||||||
|
.iter()
|
||||||
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
||||||
|
.any(|index| index.default);
|
||||||
|
|
||||||
let mut seen = FxHashSet::default();
|
let mut seen = FxHashSet::default();
|
||||||
Either::Right(
|
Either::Right(
|
||||||
self.indexes
|
self.indexes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
||||||
.filter(|index| !index.default && !index.explicit)
|
.filter(|index| !index.default && !index.explicit)
|
||||||
.chain(std::iter::once(&*VARIANT_INDEX)),
|
.chain(Some(&*VARIANT_INDEX).filter(move |_| {
|
||||||
|
// If the user defined a default index, omit the variant index.
|
||||||
|
!has_default
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -370,8 +382,7 @@ impl<'a> IndexLocations {
|
||||||
Either::Right(
|
Either::Right(
|
||||||
self.indexes
|
self.indexes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name))),
|
||||||
.chain(std::iter::once(&*VARIANT_INDEX)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -413,7 +424,6 @@ impl<'a> IndexLocations {
|
||||||
.iter()
|
.iter()
|
||||||
.chain(self.flat_index.iter())
|
.chain(self.flat_index.iter())
|
||||||
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
||||||
.chain(std::iter::once(&*VARIANT_INDEX))
|
|
||||||
} {
|
} {
|
||||||
if index.default {
|
if index.default {
|
||||||
if default {
|
if default {
|
||||||
|
|
@ -424,6 +434,7 @@ impl<'a> IndexLocations {
|
||||||
indexes.push(index);
|
indexes.push(index);
|
||||||
}
|
}
|
||||||
if !default {
|
if !default {
|
||||||
|
indexes.push(&*VARIANT_INDEX);
|
||||||
indexes.push(&*DEFAULT_INDEX);
|
indexes.push(&*DEFAULT_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -555,13 +566,24 @@ impl<'a> IndexUrls {
|
||||||
if self.no_index {
|
if self.no_index {
|
||||||
Either::Left(std::iter::empty())
|
Either::Left(std::iter::empty())
|
||||||
} else {
|
} else {
|
||||||
|
// Determine whether the user defined a default index.
|
||||||
|
let mut seen = FxHashSet::default();
|
||||||
|
let has_default = self
|
||||||
|
.indexes
|
||||||
|
.iter()
|
||||||
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
||||||
|
.any(|index| index.default);
|
||||||
|
|
||||||
let mut seen = FxHashSet::default();
|
let mut seen = FxHashSet::default();
|
||||||
Either::Right(
|
Either::Right(
|
||||||
self.indexes
|
self.indexes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
.filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
|
||||||
.filter(|index| !index.default && !index.explicit)
|
.filter(|index| !index.default && !index.explicit)
|
||||||
.chain(std::iter::once(&*VARIANT_INDEX)),
|
.chain(Some(&*VARIANT_INDEX).filter(move |_| {
|
||||||
|
// If the user defined a default index, omit the variant index.
|
||||||
|
!has_default
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -624,7 +646,7 @@ impl<'a> IndexUrls {
|
||||||
return index.status_code_strategy();
|
return index.status_code_strategy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IndexStatusCodeStrategy::Default
|
IndexStatusCodeStrategy::from_index_url(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the Simple API cache control header for an [`IndexUrl`], if configured.
|
/// Return the Simple API cache control header for an [`IndexUrl`], if configured.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue