mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue