Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repodata config to channel #530

Closed
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
13 changes: 12 additions & 1 deletion crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,24 @@ async fn fetch_repo_data_records_with_progress(
);
progress_bar.enable_steady_tick(Duration::from_millis(100));

// TODO: Should this be in some utils place?
let options = match channel.repodata_options {
Some(ref options) => FetchRepoDataOptions {
bz2_enabled: options.bz2_enabled,
jlap_enabled: options.jlap_enabled,
zstd_enabled: options.zstd_enabled,
..Default::default()
},
None => FetchRepoDataOptions::default(),
};

// Download the repodata.json
let download_progress_progress_bar = progress_bar.clone();
let result = rattler_repodata_gateway::fetch::fetch_repo_data(
channel.platform_url(platform),
client,
repodata_cache.to_path_buf(),
FetchRepoDataOptions::default(),
options,
Some(Box::new(move |DownloadProgress { total, bytes }| {
download_progress_progress_bar.set_length(total.unwrap_or(bytes));
download_progress_progress_bar.set_position(bytes);
Expand Down
44 changes: 44 additions & 0 deletions crates/rattler_conda_types/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,49 @@ pub struct ChannelConfig {
///
/// The default value is: <https://conda.anaconda.org>
pub channel_alias: Url,

/// An optional configuration for the repodata of the channel.
///
/// This *SHOULD* be used to configure how metadata is fetched from the channel.
///
pub repodata_options: Option<ChannelRepodataConfig>,
}

fn _serde_is_true(value: &bool) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefixing with _ would mean its unused. I assume you want to make it private to the module, if you dont add "pub" that should be fine.

*value
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
pub struct ChannelRepodataConfig {
/// When enabled repodata can be fetched incrementally using JLAP
#[serde(skip_serializing_if = "_serde_is_true")]
pub jlap_enabled: bool,

/// When enabled, the zstd variant will be used if available
#[serde(skip_serializing_if = "_serde_is_true")]
pub zstd_enabled: bool,

/// When enabled, the bz2 variant will be used if available
#[serde(skip_serializing_if = "_serde_is_true")]
pub bz2_enabled: bool,
}

impl Default for ChannelRepodataConfig {
fn default() -> Self {
Self {
jlap_enabled: true,
zstd_enabled: true,
bz2_enabled: true,
}
}
}

impl Default for ChannelConfig {
fn default() -> Self {
ChannelConfig {
channel_alias: Url::from_str("https://conda.anaconda.org")
.expect("could not parse default channel alias"),
repodata_options: None,
}
}
}
Expand All @@ -51,6 +87,10 @@ pub struct Channel {

/// The name of the channel
pub name: Option<String>,

/// The repodata options for this channel
#[serde(skip_serializing_if = "Option::is_none")]
pub repodata_options: Option<ChannelRepodataConfig>,
}

impl Channel {
Expand Down Expand Up @@ -80,6 +120,7 @@ impl Channel {
platforms,
base_url: url,
name: Some(channel.to_owned()),
repodata_options: config.repodata_options.clone(),
}
}
} else {
Expand Down Expand Up @@ -121,6 +162,7 @@ impl Channel {
platforms: platforms.map(Into::into),
name: (!name.is_empty()).then_some(name).map(str::to_owned),
base_url,
repodata_options: _config.repodata_options.clone(),
}
} else {
// Case 6: non-otherwise-specified file://-type urls
Expand All @@ -131,6 +173,7 @@ impl Channel {
platforms: platforms.map(Into::into),
name: (!name.is_empty()).then_some(name).map(str::to_owned),
base_url,
repodata_options: _config.repodata_options.clone(),
}
}
}
Expand All @@ -157,6 +200,7 @@ impl Channel {
.join(dir_name.as_ref())
.expect("name is not a valid Url"),
name: (!name.is_empty()).then_some(name).map(str::to_owned),
repodata_options: config.repodata_options.clone(),
}
}

Expand Down
Loading