Skip to content

Commit 52f5fb7

Browse files
committed
Extract a single-index fetch in flat index client
1 parent c1f23e4 commit 52f5fb7

File tree

10 files changed

+30
-26
lines changed

10 files changed

+30
-26
lines changed

crates/uv-client/src/flat_index.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,13 @@ impl<'a> FlatIndexClient<'a> {
107107
}
108108

109109
/// Read the directories and flat remote indexes from `--find-links`.
110-
#[allow(clippy::result_large_err)]
111-
pub async fn fetch(
110+
pub async fn fetch_all(
112111
&self,
113112
indexes: impl Iterator<Item = &IndexUrl>,
114113
) -> Result<FlatIndexEntries, FlatIndexError> {
115114
let mut fetches = futures::stream::iter(indexes)
116115
.map(|index| async move {
117-
let entries = match index {
118-
IndexUrl::Path(url) => {
119-
let path = url
120-
.to_file_path()
121-
.map_err(|()| FlatIndexError::NonFileUrl(url.to_url()))?;
122-
Self::read_from_directory(&path, index)
123-
.map_err(|err| FlatIndexError::FindLinksDirectory(path.clone(), err))?
124-
}
125-
IndexUrl::Pypi(url) | IndexUrl::Url(url) => self
126-
.read_from_url(url, index)
127-
.await
128-
.map_err(|err| FlatIndexError::FindLinksUrl(url.to_url(), err))?,
129-
};
116+
let entries = self.fetch_index(index).await?;
130117
if entries.is_empty() {
131118
warn!("No packages found in `--find-links` entry: {}", index);
132119
} else {
@@ -151,6 +138,23 @@ impl<'a> FlatIndexClient<'a> {
151138
Ok(results)
152139
}
153140

141+
/// Fetch a flat remote index from a `--find-links` URL.
142+
pub async fn fetch_index(&self, index: &IndexUrl) -> Result<FlatIndexEntries, FlatIndexError> {
143+
match index {
144+
IndexUrl::Path(url) => {
145+
let path = url
146+
.to_file_path()
147+
.map_err(|()| FlatIndexError::NonFileUrl(url.to_url()))?;
148+
Self::read_from_directory(&path, index)
149+
.map_err(|err| FlatIndexError::FindLinksDirectory(path.clone(), err))
150+
}
151+
IndexUrl::Pypi(url) | IndexUrl::Url(url) => self
152+
.read_from_url(url, index)
153+
.await
154+
.map_err(|err| FlatIndexError::FindLinksUrl(url.to_url(), err)),
155+
}
156+
}
157+
154158
/// Read a flat remote index from a `--find-links` URL.
155159
async fn read_from_url(
156160
&self,

crates/uv/src/commands/build_frontend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ async fn build_package(
552552
let flat_index = {
553553
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
554554
let entries = client
555-
.fetch(index_locations.flat_indexes().map(Index::url))
555+
.fetch_all(index_locations.flat_indexes().map(Index::url))
556556
.await?;
557557
FlatIndex::from_entries(entries, None, &hasher, build_options)
558558
};

crates/uv/src/commands/pip/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ pub(crate) async fn pip_compile(
375375
let flat_index = {
376376
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
377377
let entries = client
378-
.fetch(index_locations.flat_indexes().map(Index::url))
378+
.fetch_all(index_locations.flat_indexes().map(Index::url))
379379
.await?;
380380
FlatIndex::from_entries(entries, tags.as_deref(), &hasher, &build_options)
381381
};

crates/uv/src/commands/pip/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub(crate) async fn pip_install(
368368
let flat_index = {
369369
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
370370
let entries = client
371-
.fetch(index_locations.flat_indexes().map(Index::url))
371+
.fetch_all(index_locations.flat_indexes().map(Index::url))
372372
.await?;
373373
FlatIndex::from_entries(entries, Some(&tags), &hasher, &build_options)
374374
};

crates/uv/src/commands/pip/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub(crate) async fn pip_sync(
296296
let flat_index = {
297297
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), &cache);
298298
let entries = client
299-
.fetch(index_locations.flat_indexes().map(Index::url))
299+
.fetch_all(index_locations.flat_indexes().map(Index::url))
300300
.await?;
301301
FlatIndex::from_entries(entries, Some(&tags), &hasher, &build_options)
302302
};

crates/uv/src/commands/project/add.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ pub(crate) async fn add(
348348
let client =
349349
FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
350350
let entries = client
351-
.fetch(
351+
.fetch_all(
352352
settings
353353
.resolver
354354
.index_locations

crates/uv/src/commands/project/lock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ async fn do_lock(
636636
let flat_index = {
637637
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
638638
let entries = client
639-
.fetch(index_locations.flat_indexes().map(Index::url))
639+
.fetch_all(index_locations.flat_indexes().map(Index::url))
640640
.await?;
641641
FlatIndex::from_entries(entries, None, &hasher, build_options)
642642
};

crates/uv/src/commands/project/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ pub(crate) async fn resolve_environment(
17541754
let flat_index = {
17551755
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
17561756
let entries = client
1757-
.fetch(index_locations.flat_indexes().map(Index::url))
1757+
.fetch_all(index_locations.flat_indexes().map(Index::url))
17581758
.await?;
17591759
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
17601760
};
@@ -1897,7 +1897,7 @@ pub(crate) async fn sync_environment(
18971897
let flat_index = {
18981898
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
18991899
let entries = client
1900-
.fetch(index_locations.flat_indexes().map(Index::url))
1900+
.fetch_all(index_locations.flat_indexes().map(Index::url))
19011901
.await?;
19021902
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
19031903
};
@@ -2124,7 +2124,7 @@ pub(crate) async fn update_environment(
21242124
let flat_index = {
21252125
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
21262126
let entries = client
2127-
.fetch(index_locations.flat_indexes().map(Index::url))
2127+
.fetch_all(index_locations.flat_indexes().map(Index::url))
21282128
.await?;
21292129
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
21302130
};

crates/uv/src/commands/project/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ pub(super) async fn do_sync(
656656
let flat_index = {
657657
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
658658
let entries = client
659-
.fetch(index_locations.flat_indexes().map(Index::url))
659+
.fetch_all(index_locations.flat_indexes().map(Index::url))
660660
.await?;
661661
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
662662
};

crates/uv/src/commands/venv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async fn venv_impl(
308308
let tags = interpreter.tags().map_err(VenvError::Tags)?;
309309
let client = FlatIndexClient::new(client.cached_client(), client.connectivity(), cache);
310310
let entries = client
311-
.fetch(index_locations.flat_indexes().map(Index::url))
311+
.fetch_all(index_locations.flat_indexes().map(Index::url))
312312
.await
313313
.map_err(VenvError::FlatIndex)?;
314314
FlatIndex::from_entries(

0 commit comments

Comments
 (0)