Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/render/resolved_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use indicatif::{HumanBytes, MultiProgress, ProgressBar};
use rattler::install::Placement;
use rattler_cache::package_cache::PackageCache;
use rattler_cache::run_exports_cache::RunExportsCache;
use rattler_conda_types::{
package::RunExportsJson, ChannelUrl, MatchSpec, NamelessMatchSpec, PackageName, PackageRecord,
Platform, RepoDataRecord,
Expand Down Expand Up @@ -522,13 +522,11 @@ pub fn apply_variant(
/// Collect run exports from the package cache and add them to the package
/// records.
/// TODO: There are many ways that would allow us to optimize this function.
/// 1. This currently downloads an entire package, but we only need the
/// `run_exports.json`.
/// 2. There are special run_exports.json files available for some channels.
/// 1. There are special run_exports.json files available for some channels.
async fn amend_run_exports(
records: &mut [RepoDataRecord],
client: ClientWithMiddleware,
package_cache: PackageCache,
run_exports_cache: RunExportsCache,
multi_progress: MultiProgress,
progress_prefix: impl Into<Cow<'static, str>>,
top_level_pb: Option<ProgressBar>,
Expand All @@ -551,7 +549,7 @@ async fn amend_run_exports(
let extractor = RunExportExtractor::default()
.with_max_concurrent_requests(max_concurrent_requests.clone())
.with_client(client.clone())
.with_package_cache(package_cache.clone(), progress.clone());
.with_run_exports_cache(run_exports_cache.clone(), progress.clone());

let tx = tx.clone();
let record = pkg.clone();
Expand Down Expand Up @@ -692,7 +690,7 @@ pub(crate) async fn resolve_dependencies(
amend_run_exports(
&mut resolved,
tool_configuration.client.clone(),
tool_configuration.package_cache.clone(),
tool_configuration.run_exports_cache.clone(),
tool_configuration
.fancy_log_handler
.multi_progress()
Expand Down Expand Up @@ -788,7 +786,7 @@ pub(crate) async fn resolve_dependencies(
amend_run_exports(
&mut resolved,
tool_configuration.client.clone(),
tool_configuration.package_cache.clone(),
tool_configuration.run_exports_cache.clone(),
tool_configuration
.fancy_log_handler
.multi_progress()
Expand Down
43 changes: 23 additions & 20 deletions src/run_exports.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::sync::Arc;

use futures::future::OptionFuture;
use rattler_cache::package_cache::{CacheKey, PackageCache, PackageCacheError};
use rattler_conda_types::{
package::{PackageFile, RunExportsJson},
RepoDataRecord,
use rattler_cache::run_exports_cache::{
CacheKey, CacheKeyError, RunExportsCache, RunExportsCacheError,
};
use rattler_conda_types::{package::RunExportsJson, RepoDataRecord};
use rattler_networking::retry_policies::default_retry_policy;
use reqwest_middleware::ClientWithMiddleware;
use thiserror::Error;
Expand All @@ -20,14 +19,17 @@ use crate::package_cache_reporter::PackageCacheReporter;
#[derive(Default)]
pub struct RunExportExtractor {
max_concurrent_requests: Option<Arc<Semaphore>>,
package_cache: Option<(PackageCache, PackageCacheReporter)>,
run_exports_cache: Option<(RunExportsCache, PackageCacheReporter)>,
client: Option<ClientWithMiddleware>,
}

#[derive(Debug, Error)]
pub enum RunExportExtractorError {
#[error(transparent)]
PackageCache(#[from] PackageCacheError),
RunExportsCache(#[from] RunExportsCacheError),

#[error(transparent)]
CacheKey(#[from] CacheKeyError),

#[error("the operation was cancelled")]
Cancelled,
Expand All @@ -43,15 +45,15 @@ impl RunExportExtractor {
}
}

/// Set the package cache that the extractor can use as well as a reporter
/// Set the run exports cache that the extractor can use as well as a reporter
/// to allow progress reporting.
pub fn with_package_cache(
pub fn with_run_exports_cache(
self,
package_cache: PackageCache,
run_exports_cache: RunExportsCache,
reporter: PackageCacheReporter,
) -> Self {
Self {
package_cache: Some((package_cache, reporter)),
run_exports_cache: Some((run_exports_cache, reporter)),
..self
}
}
Expand All @@ -70,24 +72,25 @@ impl RunExportExtractor {
mut self,
record: &RepoDataRecord,
) -> Result<Option<RunExportsJson>, RunExportExtractorError> {
self.extract_into_package_cache(record).await
self.extract_into_run_exports_cache(record).await
}

/// Extract the run exports from a package by downloading it to the cache
/// and then reading the run_exports.json file.
async fn extract_into_package_cache(
/// Extract the run exports from a package by downloading and extracting only the run_exports.json file into the cache.
async fn extract_into_run_exports_cache(
&mut self,
record: &RepoDataRecord,
) -> Result<Option<RunExportsJson>, RunExportExtractorError> {
let Some((package_cache, mut package_cache_reporter)) = self.package_cache.clone() else {
let Some((run_exports_cache, mut run_exports_cache_reporter)) =
self.run_exports_cache.clone()
else {
return Ok(None);
};
let Some(client) = self.client.clone() else {
return Ok(None);
};

let progress_reporter = package_cache_reporter.add(record);
let cache_key = CacheKey::from(&record.package_record);
let progress_reporter = run_exports_cache_reporter.add(record);
let cache_key = CacheKey::create(&record.package_record, &record.file_name)?;
let url = record.url.clone();
let max_concurrent_requests = self.max_concurrent_requests.clone();

Expand All @@ -96,17 +99,17 @@ impl RunExportExtractor {
.transpose()
.expect("semaphore error");

match package_cache
match run_exports_cache
.get_or_fetch_from_url_with_retry(
cache_key,
&cache_key,
url,
client,
default_retry_policy(),
Some(Arc::new(progress_reporter)),
)
.await
{
Ok(package_dir) => Ok(RunExportsJson::from_package_directory(package_dir.path()).ok()),
Ok(cached_run_exports) => Ok(cached_run_exports.run_exports()),
Err(e) => Err(e.into()),
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/tool_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{path::PathBuf, sync::Arc};

use clap::ValueEnum;
use rattler::package_cache::PackageCache;
use rattler_cache::run_exports_cache::RunExportsCache;
use rattler_conda_types::{ChannelConfig, Platform};
use rattler_networking::{
authentication_storage::{self, AuthenticationStorageError},
Expand Down Expand Up @@ -84,6 +85,9 @@ pub struct Configuration {
/// The package cache to use to store packages in.
pub package_cache: PackageCache,

/// The run exports cache to use to store run exports in.
pub run_exports_cache: RunExportsCache,

/// The repodata gateway to use for querying repodata
pub repodata_gateway: Gateway,

Expand Down Expand Up @@ -298,6 +302,8 @@ impl ConfigurationBuilder {
reqwest_client_from_auth_storage(None).expect("failed to create client")
});
let package_cache = PackageCache::new(cache_dir.join(rattler_cache::PACKAGE_CACHE_DIR));
let run_exports_cache =
RunExportsCache::new(cache_dir.join(rattler_cache::RUN_EXPORTS_CACHE_DIR));
let channel_config = self.channel_config.unwrap_or_else(|| {
ChannelConfig::default_with_root_dir(
std::env::current_dir().unwrap_or_else(|_err| PathBuf::from("/")),
Expand Down Expand Up @@ -336,6 +342,7 @@ impl ConfigurationBuilder {
channel_config,
compression_threads: self.compression_threads,
package_cache,
run_exports_cache,
repodata_gateway,
channel_priority: self.channel_priority,
}
Expand Down
Loading