Skip to content

Commit

Permalink
Change constructor calls to new_singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinou01 committed Sep 3, 2024
1 parent b428ca2 commit 2b04cf5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 40 deletions.
4 changes: 2 additions & 2 deletions crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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())
Expand Down
18 changes: 9 additions & 9 deletions crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionOperation<PrefixRecord, RepoDataRecord>> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions crates/rattler/src/install/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PrefixRecord>>,
package_cache: Option<SingletonPackageCache>,
package_cache: Option<PackageCache>,
downloader: Option<reqwest_middleware::ClientWithMiddleware>,
execute_link_scripts: bool,
io_semaphore: Option<Arc<Semaphore>>,
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<dyn Reporter>, usize)>,
) -> Result<PathBuf, InstallerError> {
struct CacheReporterBridge {
Expand Down
4 changes: 2 additions & 2 deletions crates/rattler/src/install/link_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
test_utils::execute_transaction, transaction, InstallDriver, InstallOptions,
TransactionOperation,
},
package_cache::SingletonPackageCache,
package_cache::PackageCache,
};

fn test_operations() -> Vec<TransactionOperation<PrefixRecord, RepoDataRecord>> {
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions crates/rattler/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler/src/install/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PrefixRecord, RepoDataRecord>,
install_options: &InstallOptions,
Expand Down Expand Up @@ -121,7 +121,7 @@ pub async fn execute_transaction(
transaction: Transaction<PrefixRecord, RepoDataRecord>,
target_prefix: &Path,
download_client: &reqwest_middleware::ClientWithMiddleware,
package_cache: &SingletonPackageCache,
package_cache: &PackageCache,
install_driver: &InstallDriver,
install_options: &InstallOptions,
) {
Expand Down
10 changes: 5 additions & 5 deletions crates/rattler_repodata_gateway/src/gateway/builder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +13,7 @@ pub struct GatewayBuilder {
channel_config: ChannelConfig,
client: Option<ClientWithMiddleware>,
cache: Option<PathBuf>,
package_cache: Option<SingletonPackageCache>,
package_cache: Option<PackageCache>,
max_concurrent_requests: Option<usize>,
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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),
));

Expand Down
12 changes: 6 additions & 6 deletions crates/rattler_repodata_gateway/src/gateway/direct_url_query.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)]
Expand All @@ -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<Sha256Hash>,
) -> Self {
Expand Down Expand Up @@ -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::*;
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions crates/rattler_repodata_gateway/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<tokio::sync::Semaphore>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 2b04cf5

Please sign in to comment.