Remove the flat index types (#7759)

## Summary

I think these really don't pull their weight.
This commit is contained in:
Charlie Marsh 2024-10-15 16:30:37 -07:00 committed by GitHub
parent d31b995511
commit a034a8b83b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 158 additions and 315 deletions

View file

@ -5,13 +5,14 @@ use reqwest::Response;
use tracing::{debug, info_span, warn, Instrument};
use url::Url;
use crate::cached_client::{CacheControl, CachedClientError};
use crate::html::SimpleHtml;
use crate::{Connectivity, Error, ErrorKind, OwnedArchive, RegistryClient};
use uv_cache::{Cache, CacheBucket};
use uv_cache_key::cache_digest;
use uv_distribution_filename::DistFilename;
use uv_distribution_types::{File, FileLocation, FlatIndexLocation, IndexUrl, UrlString};
use uv_distribution_types::{File, FileLocation, IndexUrl, UrlString};
use crate::cached_client::{CacheControl, CachedClientError};
use crate::html::SimpleHtml;
use crate::{Connectivity, Error, ErrorKind, OwnedArchive, RegistryClient};
#[derive(Debug, thiserror::Error)]
pub enum FlatIndexError {
@ -94,19 +95,19 @@ impl<'a> FlatIndexClient<'a> {
#[allow(clippy::result_large_err)]
pub async fn fetch(
&self,
indexes: impl Iterator<Item = &FlatIndexLocation>,
indexes: impl Iterator<Item = &IndexUrl>,
) -> Result<FlatIndexEntries, FlatIndexError> {
let mut fetches = futures::stream::iter(indexes)
.map(|index| async move {
let entries = match index {
FlatIndexLocation::Path(url) => {
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))?
}
FlatIndexLocation::Url(url) => self
IndexUrl::Pypi(url) | IndexUrl::Url(url) => self
.read_from_url(url, index)
.await
.map_err(|err| FlatIndexError::FindLinksUrl(url.to_url(), err))?,
@ -136,7 +137,7 @@ impl<'a> FlatIndexClient<'a> {
async fn read_from_url(
&self,
url: &Url,
flat_index: &FlatIndexLocation,
flat_index: &IndexUrl,
) -> Result<FlatIndexEntries, Error> {
let cache_entry = self.cache.entry(
CacheBucket::FlatIndex,
@ -210,7 +211,7 @@ impl<'a> FlatIndexClient<'a> {
Some((
DistFilename::try_from_normalized_filename(&file.filename)?,
file,
IndexUrl::from(flat_index.clone()),
flat_index.clone(),
))
})
.collect();
@ -226,7 +227,7 @@ impl<'a> FlatIndexClient<'a> {
/// Read a flat remote index from a `--find-links` directory.
fn read_from_directory(
path: &Path,
flat_index: &FlatIndexLocation,
flat_index: &IndexUrl,
) -> Result<FlatIndexEntries, FindLinksDirectoryError> {
let mut dists = Vec::new();
for entry in fs_err::read_dir(path)? {
@ -279,7 +280,7 @@ impl<'a> FlatIndexClient<'a> {
);
continue;
};
dists.push((filename, file, IndexUrl::from(flat_index.clone())));
dists.push((filename, file, flat_index.clone()));
}
Ok(FlatIndexEntries::from_entries(dists))
}