mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 10:33:49 +00:00
Extract a single-index fetch in flat index client (#12394)
This commit is contained in:
parent
2250ddedbf
commit
9af989e30c
10 changed files with 30 additions and 26 deletions
|
@ -107,26 +107,13 @@ impl<'a> FlatIndexClient<'a> {
|
|||
}
|
||||
|
||||
/// Read the directories and flat remote indexes from `--find-links`.
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub async fn fetch(
|
||||
pub async fn fetch_all(
|
||||
&self,
|
||||
indexes: impl Iterator<Item = &IndexUrl>,
|
||||
) -> Result<FlatIndexEntries, FlatIndexError> {
|
||||
let mut fetches = futures::stream::iter(indexes)
|
||||
.map(|index| async move {
|
||||
let entries = match index {
|
||||
IndexUrl::Path(url) => {
|
||||
let path = url
|
||||
.to_file_path()
|
||||
.map_err(|()| FlatIndexError::NonFileUrl(url.to_url()))?;
|
||||
Self::read_from_directory(&path, index)
|
||||
.map_err(|err| FlatIndexError::FindLinksDirectory(path.clone(), err))?
|
||||
}
|
||||
IndexUrl::Pypi(url) | IndexUrl::Url(url) => self
|
||||
.read_from_url(url, index)
|
||||
.await
|
||||
.map_err(|err| FlatIndexError::FindLinksUrl(url.to_url(), err))?,
|
||||
};
|
||||
let entries = self.fetch_index(index).await?;
|
||||
if entries.is_empty() {
|
||||
warn!("No packages found in `--find-links` entry: {}", index);
|
||||
} else {
|
||||
|
@ -151,6 +138,23 @@ impl<'a> FlatIndexClient<'a> {
|
|||
Ok(results)
|
||||
}
|
||||
|
||||
/// Fetch a flat remote index from a `--find-links` URL.
|
||||
pub async fn fetch_index(&self, index: &IndexUrl) -> Result<FlatIndexEntries, FlatIndexError> {
|
||||
match index {
|
||||
IndexUrl::Path(url) => {
|
||||
let path = url
|
||||
.to_file_path()
|
||||
.map_err(|()| FlatIndexError::NonFileUrl(url.to_url()))?;
|
||||
Self::read_from_directory(&path, index)
|
||||
.map_err(|err| FlatIndexError::FindLinksDirectory(path.clone(), err))
|
||||
}
|
||||
IndexUrl::Pypi(url) | IndexUrl::Url(url) => self
|
||||
.read_from_url(url, index)
|
||||
.await
|
||||
.map_err(|err| FlatIndexError::FindLinksUrl(url.to_url(), err)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a flat remote index from a `--find-links` URL.
|
||||
async fn read_from_url(
|
||||
&self,
|
||||
|
|
|
@ -552,7 +552,7 @@ async fn build_package(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, None, &hasher, build_options)
|
||||
};
|
||||
|
|
|
@ -375,7 +375,7 @@ pub(crate) async fn pip_compile(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, tags.as_deref(), &hasher, &build_options)
|
||||
};
|
||||
|
|
|
@ -368,7 +368,7 @@ pub(crate) async fn pip_install(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(&tags), &hasher, &build_options)
|
||||
};
|
||||
|
|
|
@ -296,7 +296,7 @@ pub(crate) async fn pip_sync(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(&tags), &hasher, &build_options)
|
||||
};
|
||||
|
|
|
@ -348,7 +348,7 @@ pub(crate) async fn add(
|
|||
let client =
|
||||
FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(
|
||||
.fetch_all(
|
||||
settings
|
||||
.resolver
|
||||
.index_locations
|
||||
|
|
|
@ -636,7 +636,7 @@ async fn do_lock(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, None, &hasher, build_options)
|
||||
};
|
||||
|
|
|
@ -1754,7 +1754,7 @@ pub(crate) async fn resolve_environment(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
|
||||
};
|
||||
|
@ -1897,7 +1897,7 @@ pub(crate) async fn sync_environment(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
|
||||
};
|
||||
|
@ -2124,7 +2124,7 @@ pub(crate) async fn update_environment(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
|
||||
};
|
||||
|
|
|
@ -656,7 +656,7 @@ pub(super) async fn do_sync(
|
|||
let flat_index = {
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await?;
|
||||
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
|
||||
};
|
||||
|
|
|
@ -308,7 +308,7 @@ async fn venv_impl(
|
|||
let tags = interpreter.tags().map_err(VenvError::Tags)?;
|
||||
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
|
||||
let entries = client
|
||||
.fetch(index_locations.flat_indexes().map(Index::url))
|
||||
.fetch_all(index_locations.flat_indexes().map(Index::url))
|
||||
.await
|
||||
.map_err(VenvError::FlatIndex)?;
|
||||
FlatIndex::from_entries(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue