Skip to content

Commit 232435c

Browse files
charliermarshpull[bot]
authored andcommitted
Remove Cache argument from DistributionDatabase (#2749)
## Summary We can access cache from `BuildContext`. This mirrors `SourceDistCachedBuilder`, which doesn't accept `Cache` as an argument and always accesses it through `BuildContext`.
1 parent 137e51a commit 232435c

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

crates/uv-distribution/src/distribution_database.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use distribution_types::{
1515
};
1616
use platform_tags::Tags;
1717
use pypi_types::Metadata23;
18-
use uv_cache::{ArchiveTarget, ArchiveTimestamp, Cache, CacheBucket, CacheEntry, WheelCache};
18+
use uv_cache::{ArchiveTarget, ArchiveTimestamp, CacheBucket, CacheEntry, WheelCache};
1919
use uv_client::{CacheControl, CachedClientError, Connectivity, RegistryClient};
2020
use uv_types::{BuildContext, NoBinary, NoBuild};
2121

@@ -37,23 +37,21 @@ use crate::{DiskWheel, Error, LocalWheel, Reporter, SourceDistCachedBuilder};
3737
/// This struct also has the task of acquiring locks around source dist builds in general and git
3838
/// operation especially.
3939
pub struct DistributionDatabase<'a, Context: BuildContext + Send + Sync> {
40-
cache: &'a Cache,
41-
reporter: Option<Arc<dyn Reporter>>,
42-
locks: Arc<Locks>,
4340
client: &'a RegistryClient,
4441
build_context: &'a Context,
4542
builder: SourceDistCachedBuilder<'a, Context>,
43+
locks: Arc<Locks>,
44+
reporter: Option<Arc<dyn Reporter>>,
4645
}
4746

4847
impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context> {
49-
pub fn new(cache: &'a Cache, client: &'a RegistryClient, build_context: &'a Context) -> Self {
48+
pub fn new(client: &'a RegistryClient, build_context: &'a Context) -> Self {
5049
Self {
51-
cache,
52-
reporter: None,
53-
locks: Arc::new(Locks::default()),
5450
client,
5551
build_context,
5652
builder: SourceDistCachedBuilder::new(build_context, client),
53+
locks: Arc::new(Locks::default()),
54+
reporter: None,
5755
}
5856
}
5957

@@ -200,7 +198,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
200198
}
201199
FileLocation::Path(path) => {
202200
let url = Url::from_file_path(path).expect("path is absolute");
203-
let cache_entry = self.cache.entry(
201+
let cache_entry = self.build_context.cache().entry(
204202
CacheBucket::Wheels,
205203
WheelCache::Url(&url).wheel_dir(wheel.name().as_ref()),
206204
wheel.filename.stem(),
@@ -238,7 +236,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
238236
};
239237

240238
// Create a cache entry for the wheel.
241-
let wheel_entry = self.cache.entry(
239+
let wheel_entry = self.build_context.cache().entry(
242240
CacheBucket::Wheels,
243241
WheelCache::Index(&wheel.index).wheel_dir(wheel.name().as_ref()),
244242
wheel.filename.stem(),
@@ -276,7 +274,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
276274

277275
BuiltDist::DirectUrl(wheel) => {
278276
// Create a cache entry for the wheel.
279-
let wheel_entry = self.cache.entry(
277+
let wheel_entry = self.build_context.cache().entry(
280278
CacheBucket::Wheels,
281279
WheelCache::Url(&wheel.url).wheel_dir(wheel.name().as_ref()),
282280
wheel.filename.stem(),
@@ -318,7 +316,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
318316
}
319317

320318
BuiltDist::Path(wheel) => {
321-
let cache_entry = self.cache.entry(
319+
let cache_entry = self.build_context.cache().entry(
322320
CacheBucket::Wheels,
323321
WheelCache::Url(&wheel.url).wheel_dir(wheel.name().as_ref()),
324322
wheel.filename.stem(),
@@ -406,13 +404,14 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
406404
.into_async_read();
407405

408406
// Download and unzip the wheel to a temporary directory.
409-
let temp_dir =
410-
tempfile::tempdir_in(self.cache.root()).map_err(Error::CacheWrite)?;
407+
let temp_dir = tempfile::tempdir_in(self.build_context.cache().root())
408+
.map_err(Error::CacheWrite)?;
411409
uv_extract::stream::unzip(reader.compat(), temp_dir.path()).await?;
412410

413411
// Persist the temporary directory to the directory store.
414412
let archive = self
415-
.cache
413+
.build_context
414+
.cache()
416415
.persist(temp_dir.into_path(), wheel_entry.path())
417416
.await
418417
.map_err(Error::CacheRead)?;
@@ -435,7 +434,8 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
435434
.build()?;
436435
let cache_control = match self.client.connectivity() {
437436
Connectivity::Online => CacheControl::from(
438-
self.cache
437+
self.build_context
438+
.cache()
439439
.freshness(&http_entry, Some(&filename.name))
440440
.map_err(Error::CacheRead)?,
441441
),
@@ -474,16 +474,16 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
474474
.into_async_read();
475475

476476
// Download the wheel to a temporary file.
477-
let temp_file =
478-
tempfile::tempfile_in(self.cache.root()).map_err(Error::CacheWrite)?;
477+
let temp_file = tempfile::tempfile_in(self.build_context.cache().root())
478+
.map_err(Error::CacheWrite)?;
479479
let mut writer = tokio::io::BufWriter::new(tokio::fs::File::from_std(temp_file));
480480
tokio::io::copy(&mut reader.compat(), &mut writer)
481481
.await
482482
.map_err(Error::CacheWrite)?;
483483

484484
// Unzip the wheel to a temporary directory.
485-
let temp_dir =
486-
tempfile::tempdir_in(self.cache.root()).map_err(Error::CacheWrite)?;
485+
let temp_dir = tempfile::tempdir_in(self.build_context.cache().root())
486+
.map_err(Error::CacheWrite)?;
487487
let mut file = writer.into_inner();
488488
file.seek(io::SeekFrom::Start(0))
489489
.await
@@ -493,7 +493,8 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
493493

494494
// Persist the temporary directory to the directory store.
495495
let archive = self
496-
.cache
496+
.build_context
497+
.cache()
497498
.persist(temp_dir.into_path(), wheel_entry.path())
498499
.await
499500
.map_err(Error::CacheRead)?;
@@ -516,7 +517,8 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
516517
.build()?;
517518
let cache_control = match self.client.connectivity() {
518519
Connectivity::Online => CacheControl::from(
519-
self.cache
520+
self.build_context
521+
.cache()
520522
.freshness(&http_entry, Some(&filename.name))
521523
.map_err(Error::CacheRead)?,
522524
),

crates/uv-installer/src/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a, Context: BuildContext + Send + Sync> Downloader<'a, Context> {
5454
Self {
5555
tags,
5656
cache,
57-
database: DistributionDatabase::new(cache, client, build_context),
57+
database: DistributionDatabase::new(client, build_context),
5858
reporter: None,
5959
}
6060
}

crates/uv-resolver/src/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<
140140
) -> Result<Self, ResolveError> {
141141
let provider = DefaultResolverProvider::new(
142142
client,
143-
DistributionDatabase::new(build_context.cache(), client, build_context),
143+
DistributionDatabase::new(client, build_context),
144144
flat_index,
145145
tags,
146146
PythonRequirement::new(interpreter, markers),

0 commit comments

Comments
 (0)