diff --git a/crates/rattler-bin/src/commands/create.rs b/crates/rattler-bin/src/commands/create.rs index 3e42f2b4e..18c103923 100644 --- a/crates/rattler-bin/src/commands/create.rs +++ b/crates/rattler-bin/src/commands/create.rs @@ -4,7 +4,7 @@ use clap::ValueEnum; use indicatif::{ProgressBar, ProgressStyle}; use itertools::Itertools; use rattler::install::{IndicatifReporter, Installer}; -use rattler::package_cache::SingletonPackageCache; +use rattler::package_cache::PackageCache; use rattler::{ default_cache_dir, install::{Transaction, TransactionOperation}, @@ -145,7 +145,7 @@ pub async fn create(opt: Opt) -> anyhow::Result<()> { // Get the package names from the matchspecs so we can only load the package records that we need. let gateway = Gateway::builder() .with_cache_dir(cache_dir.join(rattler_cache::REPODATA_CACHE_DIR)) - .with_package_cache(SingletonPackageCache::new( + .with_package_cache(PackageCache::new_singleton( cache_dir.join(rattler_cache::PACKAGE_CACHE_DIR), )) .with_client(download_client.clone()) diff --git a/crates/rattler/src/install/clobber_registry.rs b/crates/rattler/src/install/clobber_registry.rs index 54f2079f6..0a471f6c7 100644 --- a/crates/rattler/src/install/clobber_registry.rs +++ b/crates/rattler/src/install/clobber_registry.rs @@ -371,7 +371,7 @@ mod tests { use crate::{ get_repodata_record, get_test_data_dir, install::{test_utils::*, transaction, InstallDriver, InstallOptions, PythonInfo}, - package_cache::SingletonPackageCache, + package_cache::PackageCache, }; fn test_operations() -> Vec> { @@ -476,7 +476,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -597,7 +597,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -679,7 +679,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -782,7 +782,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -883,7 +883,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -1013,7 +1013,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); let install_options = InstallOptions { python_info: Some(python_info.clone()), @@ -1062,7 +1062,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, @@ -1129,7 +1129,7 @@ mod tests { let target_prefix = tempfile::tempdir().unwrap(); let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); execute_transaction( transaction, diff --git a/crates/rattler/src/install/installer/mod.rs b/crates/rattler/src/install/installer/mod.rs index fdb6b2449..008903cd6 100644 --- a/crates/rattler/src/install/installer/mod.rs +++ b/crates/rattler/src/install/installer/mod.rs @@ -31,14 +31,14 @@ use crate::install::link_script::LinkScriptError; use crate::{ default_cache_dir, install::{clobber_registry::ClobberedPath, link_script::PrePostLinkResult}, - package_cache::{CacheReporter, SingletonPackageCache}, + package_cache::{CacheReporter, PackageCache}, }; /// An installer that can install packages into a prefix. #[derive(Default)] pub struct Installer { installed: Option>, - package_cache: Option, + package_cache: Option, downloader: Option, execute_link_scripts: bool, io_semaphore: Option>, @@ -142,7 +142,7 @@ impl Installer { /// Sets the package cache to use. #[must_use] - pub fn with_package_cache(self, package_cache: SingletonPackageCache) -> Self { + pub fn with_package_cache(self, package_cache: PackageCache) -> Self { Self { package_cache: Some(package_cache), ..self @@ -153,7 +153,7 @@ impl Installer { /// /// This function is similar to [`Self::with_package_cache`],but modifies an /// existing instance. - pub fn set_package_cache(&mut self, package_cache: SingletonPackageCache) -> &mut Self { + pub fn set_package_cache(&mut self, package_cache: PackageCache) -> &mut Self { self.package_cache = Some(package_cache); self } @@ -274,7 +274,7 @@ impl Installer { .downloader .unwrap_or_else(|| reqwest_middleware::ClientWithMiddleware::from(Client::default())); let package_cache = self.package_cache.unwrap_or_else(|| { - SingletonPackageCache::new( + PackageCache::new_singleton( default_cache_dir() .expect("failed to determine default cache directory") .join(rattler_cache::PACKAGE_CACHE_DIR), @@ -517,7 +517,7 @@ async fn link_package( async fn populate_cache( record: &RepoDataRecord, downloader: reqwest_middleware::ClientWithMiddleware, - cache: &SingletonPackageCache, + cache: &PackageCache, reporter: Option<(Arc, usize)>, ) -> Result { struct CacheReporterBridge { diff --git a/crates/rattler/src/install/link_script.rs b/crates/rattler/src/install/link_script.rs index 9fb7742a9..dd3af5d01 100644 --- a/crates/rattler/src/install/link_script.rs +++ b/crates/rattler/src/install/link_script.rs @@ -239,7 +239,7 @@ mod tests { test_utils::execute_transaction, transaction, InstallDriver, InstallOptions, TransactionOperation, }, - package_cache::SingletonPackageCache, + package_cache::PackageCache, }; fn test_operations() -> Vec> { @@ -264,7 +264,7 @@ mod tests { }; let packages_dir = tempfile::tempdir().unwrap(); - let cache = SingletonPackageCache::new(packages_dir.path()); + let cache = PackageCache::new_singleton(packages_dir.path()); let driver = InstallDriver::builder().execute_link_scripts(true).finish(); execute_transaction( diff --git a/crates/rattler/src/install/mod.rs b/crates/rattler/src/install/mod.rs index 9fa99f926..b423d2e77 100644 --- a/crates/rattler/src/install/mod.rs +++ b/crates/rattler/src/install/mod.rs @@ -723,7 +723,7 @@ mod test { use crate::{ get_test_data_dir, install::{link_package, InstallDriver, InstallOptions, PythonInfo}, - package_cache::SingletonPackageCache, + package_cache::PackageCache, }; #[tracing_test::traced_test] @@ -777,7 +777,8 @@ mod test { // Open a package cache in the systems temporary directory with a specific name. // This allows us to reuse a package cache across multiple invocations // of this test. Useful if you're debugging. - let package_cache = SingletonPackageCache::new(temp_dir().join("rattler").join(cache_name)); + let package_cache = + PackageCache::new_singleton(temp_dir().join("rattler").join(cache_name)); // Create an HTTP client we can use to download packages let client = reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()); diff --git a/crates/rattler/src/install/test_utils.rs b/crates/rattler/src/install/test_utils.rs index 2b8fb2ca4..4a2a17786 100644 --- a/crates/rattler/src/install/test_utils.rs +++ b/crates/rattler/src/install/test_utils.rs @@ -7,7 +7,7 @@ use transaction::{Transaction, TransactionOperation}; use crate::{ install::{transaction, unlink_package, InstallDriver, InstallOptions}, - package_cache::SingletonPackageCache, + package_cache::PackageCache, }; /// Install a package into the environment and write a `conda-meta` file that @@ -69,7 +69,7 @@ pub async fn install_package_to_environment( pub async fn execute_operation( target_prefix: &Path, download_client: &reqwest_middleware::ClientWithMiddleware, - package_cache: &SingletonPackageCache, + package_cache: &PackageCache, install_driver: &InstallDriver, op: TransactionOperation, install_options: &InstallOptions, @@ -121,7 +121,7 @@ pub async fn execute_transaction( transaction: Transaction, target_prefix: &Path, download_client: &reqwest_middleware::ClientWithMiddleware, - package_cache: &SingletonPackageCache, + package_cache: &PackageCache, install_driver: &InstallDriver, install_options: &InstallOptions, ) { diff --git a/crates/rattler_repodata_gateway/src/gateway/builder.rs b/crates/rattler_repodata_gateway/src/gateway/builder.rs index b90dfd61d..fc79dc85e 100644 --- a/crates/rattler_repodata_gateway/src/gateway/builder.rs +++ b/crates/rattler_repodata_gateway/src/gateway/builder.rs @@ -1,7 +1,7 @@ use crate::gateway::GatewayInner; use crate::{ChannelConfig, Gateway}; use dashmap::DashMap; -use rattler_cache::package_cache::SingletonPackageCache; +use rattler_cache::package_cache::PackageCache; use reqwest::Client; use reqwest_middleware::ClientWithMiddleware; use std::path::PathBuf; @@ -13,7 +13,7 @@ pub struct GatewayBuilder { channel_config: ChannelConfig, client: Option, cache: Option, - package_cache: Option, + package_cache: Option, max_concurrent_requests: Option, } @@ -57,7 +57,7 @@ impl GatewayBuilder { } /// Add package cache to the builder to store packages. - pub fn with_package_cache(mut self, package_cache: SingletonPackageCache) -> Self { + pub fn with_package_cache(mut self, package_cache: PackageCache) -> Self { self.set_package_cache(package_cache); self } @@ -69,7 +69,7 @@ impl GatewayBuilder { } /// Set the directory to use for caching packages. - pub fn set_package_cache(&mut self, package_cache: SingletonPackageCache) -> &mut Self { + pub fn set_package_cache(&mut self, package_cache: PackageCache) -> &mut Self { self.package_cache = Some(package_cache); self } @@ -99,7 +99,7 @@ impl GatewayBuilder { .join("rattler/cache") }); - let package_cache = self.package_cache.unwrap_or(SingletonPackageCache::new( + let package_cache = self.package_cache.unwrap_or(PackageCache::new_singleton( cache.join(rattler_cache::PACKAGE_CACHE_DIR), )); diff --git a/crates/rattler_repodata_gateway/src/gateway/direct_url_query.rs b/crates/rattler_repodata_gateway/src/gateway/direct_url_query.rs index 267d92732..7bbaf6382 100644 --- a/crates/rattler_repodata_gateway/src/gateway/direct_url_query.rs +++ b/crates/rattler_repodata_gateway/src/gateway/direct_url_query.rs @@ -1,7 +1,7 @@ use std::{future::IntoFuture, sync::Arc}; use futures::FutureExt; -use rattler_cache::package_cache::{CacheKey, PackageCacheError}; +use rattler_cache::package_cache::{CacheKey, PackageCache, PackageCacheError}; use rattler_conda_types::{ package::{ArchiveIdentifier, IndexJson, PackageFile}, ConvertSubdirError, PackageRecord, RepoDataRecord, @@ -17,7 +17,7 @@ pub(crate) struct DirectUrlQuery { /// The client to use for fetching the package client: reqwest_middleware::ClientWithMiddleware, /// The cache to use for storing the package - package_cache: SingletonPackageCache, + package_cache: PackageCache, } #[derive(Debug, thiserror::Error)] @@ -35,7 +35,7 @@ pub enum DirectUrlQueryError { impl DirectUrlQuery { pub(crate) fn new( url: Url, - package_cache: SingletonPackageCache, + package_cache: PackageCache, client: reqwest_middleware::ClientWithMiddleware, sha256: Option, ) -> Self { @@ -110,7 +110,7 @@ impl IntoFuture for DirectUrlQuery { mod test { use std::{env::temp_dir, path::PathBuf}; - use rattler_cache::package_cache::SingletonPackageCache; + use rattler_cache::package_cache::PackageCache; use url::Url; use super::*; @@ -121,7 +121,7 @@ mod test { "https://conda.anaconda.org/conda-forge/noarch/boltons-24.0.0-pyhd8ed1ab_0.conda", ) .unwrap(); - let package_cache = SingletonPackageCache::new(PathBuf::from("/tmp")); + let package_cache = PackageCache::new_singleton(PathBuf::from("/tmp")); let client = reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()); let query = DirectUrlQuery::new(url.clone(), package_cache, client, None); @@ -163,7 +163,7 @@ mod test { .unwrap(); let url = Url::from_file_path(package_path).unwrap(); - let package_cache = SingletonPackageCache::new(temp_dir()); + let package_cache = PackageCache::new_singleton(temp_dir()); let client = reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()); let query = DirectUrlQuery::new(url.clone(), package_cache, client, None); diff --git a/crates/rattler_repodata_gateway/src/gateway/mod.rs b/crates/rattler_repodata_gateway/src/gateway/mod.rs index 2fb2eb31f..e914ecbbd 100644 --- a/crates/rattler_repodata_gateway/src/gateway/mod.rs +++ b/crates/rattler_repodata_gateway/src/gateway/mod.rs @@ -24,7 +24,7 @@ pub use error::GatewayError; use file_url::url_to_path; use local_subdir::LocalSubdirClient; pub use query::{NamesQuery, RepoDataQuery}; -use rattler_cache::package_cache::SingletonPackageCache; +use rattler_cache::package_cache::PackageCache; use rattler_conda_types::{Channel, MatchSpec, Platform}; pub use repo_data::RepoData; use reqwest_middleware::ClientWithMiddleware; @@ -161,7 +161,7 @@ struct GatewayInner { cache: PathBuf, /// The package cache, stored to reuse memory cache - package_cache: SingletonPackageCache, + package_cache: PackageCache, /// A semaphore to limit the number of concurrent requests. concurrent_requests_semaphore: Arc, @@ -362,7 +362,7 @@ mod test { use dashmap::DashSet; use rattler_cache::default_cache_dir; - use rattler_cache::package_cache::SingletonPackageCache; + use rattler_cache::package_cache::PackageCache; use rattler_conda_types::{ Channel, ChannelConfig, MatchSpec, PackageName, ParseStrictness::Lenient, ParseStrictness::Strict, Platform, RepoDataRecord, @@ -433,7 +433,7 @@ mod test { #[tokio::test] async fn test_direct_url_spec_from_gateway() { let gateway = Gateway::builder() - .with_package_cache(SingletonPackageCache::new( + .with_package_cache(PackageCache::new_singleton( default_cache_dir() .unwrap() .join(rattler_cache::PACKAGE_CACHE_DIR), @@ -494,7 +494,7 @@ mod test { #[tokio::test] async fn test_select_forced_url_instead_of_deps() { let gateway = Gateway::builder() - .with_package_cache(SingletonPackageCache::new( + .with_package_cache(PackageCache::new_singleton( default_cache_dir() .unwrap() .join(rattler_cache::PACKAGE_CACHE_DIR),