Skip to content

Commit

Permalink
feat: add --channel-priority={strict|disabled} (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-hbk authored Nov 27, 2024
1 parent d201265 commit 586982d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{path::PathBuf, vec};

use miette::{Context, IntoDiagnostic};
use rattler_conda_types::{Channel, MatchSpec, ParseStrictness, Platform};
use rattler_solve::{ChannelPriority, SolveStrategy};
use rattler_solve::SolveStrategy;

use crate::{
metadata::{build_reindexed_channels, Output},
Expand Down Expand Up @@ -196,7 +196,7 @@ pub async fn run_build(
channels: build_reindexed_channels(&output.build_configuration, tool_configuration)
.into_diagnostic()
.context("failed to reindex output channel")?,
channel_priority: ChannelPriority::Strict,
channel_priority: tool_configuration.channel_priority,
solve_strategy: SolveStrategy::Highest,
tool_configuration: tool_configuration.clone(),
},
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use opt::*;
use package_test::TestConfiguration;
use petgraph::{algo::toposort, graph::DiGraph, visit::DfsPostOrder};
use rattler_conda_types::{package::ArchiveType, Channel, GenericVirtualPackage, Platform};
use rattler_solve::{ChannelPriority, SolveStrategy};
use rattler_solve::SolveStrategy;
use rattler_virtual_packages::{VirtualPackage, VirtualPackageOverrides};
use recipe::{
parser::{find_outputs_from_src, Dependency, Recipe},
Expand Down Expand Up @@ -136,6 +136,7 @@ pub fn get_tool_config(
.with_bz2_repodata_enabled(args.common.use_zstd)
.with_skip_existing(args.skip_existing)
.with_noarch_build_platform(args.noarch_build_platform)
.with_channel_priority(args.common.channel_priority.value)
.finish())
}

Expand Down Expand Up @@ -348,7 +349,7 @@ pub async fn get_build_output(
)
.into_diagnostic()?,
channels,
channel_priority: ChannelPriority::Strict,
channel_priority: tool_config.channel_priority,
solve_strategy: SolveStrategy::Highest,
timestamp,
subpackages: subpackages.clone(),
Expand Down Expand Up @@ -467,6 +468,7 @@ pub async fn run_test_from_args(
)
.with_zstd_repodata_enabled(args.common.use_zstd)
.with_bz2_repodata_enabled(args.common.use_zstd)
.with_channel_priority(args.common.channel_priority.value)
.finish();

let channels = args
Expand All @@ -486,7 +488,7 @@ pub async fn run_test_from_args(
current_platform,
keep_test_prefix: false,
channels,
channel_priority: ChannelPriority::Strict,
channel_priority: tool_config.channel_priority,
solve_strategy: SolveStrategy::Highest,
tool_configuration: tool_config,
};
Expand Down
28 changes: 28 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap_complete_nushell::Nushell;
use clap_verbosity_flag::{InfoLevel, Verbosity};
use rattler_conda_types::{package::ArchiveType, Platform};
use rattler_package_streaming::write::CompressionLevel;
use rattler_solve::ChannelPriority;
use serde_json::{json, Value};
use url::Url;

Expand Down Expand Up @@ -194,6 +195,33 @@ pub struct CommonOpts {
/// Path to an auth-file to read authentication information from
#[clap(long, env = "RATTLER_AUTH_FILE", hide = true)]
pub auth_file: Option<PathBuf>,

/// Channel priority to use when solving
#[arg(long, default_value = "strict")]
pub channel_priority: ChannelPriorityWrapper,
}

/// Container for rattler_solver::ChannelPriority so that it can be parsed
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ChannelPriorityWrapper {
/// The ChannelPriority value to be used when building the Configuration
pub value: ChannelPriority,
}

impl FromStr for ChannelPriorityWrapper {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"strict" => Ok(ChannelPriorityWrapper {
value: ChannelPriority::Strict,
}),
"disabled" => Ok(ChannelPriorityWrapper {
value: ChannelPriority::Disabled,
}),
_ => Err("Channel priority must be either 'strict' or 'disabled'".to_string()),
}
}
}

/// Container for the CLI package format and compression level
Expand Down
15 changes: 15 additions & 0 deletions src/tool_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rattler_networking::{
AuthenticationMiddleware, AuthenticationStorage,
};
use rattler_repodata_gateway::Gateway;
use rattler_solve::ChannelPriority;
use reqwest_middleware::ClientWithMiddleware;

use crate::console_utils::LoggingOutputHandler;
Expand Down Expand Up @@ -84,6 +85,9 @@ pub struct Configuration {

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

/// What channel priority to use in solving
pub channel_priority: ChannelPriority,
}

/// Get the authentication storage from the given file
Expand Down Expand Up @@ -136,6 +140,7 @@ pub struct ConfigurationBuilder {
noarch_build_platform: Option<Platform>,
channel_config: Option<ChannelConfig>,
compression_threads: Option<u32>,
channel_priority: ChannelPriority,
}

impl Configuration {
Expand All @@ -161,6 +166,7 @@ impl ConfigurationBuilder {
noarch_build_platform: None,
channel_config: None,
compression_threads: None,
channel_priority: ChannelPriority::Strict,
}
}

Expand Down Expand Up @@ -269,6 +275,14 @@ impl ConfigurationBuilder {
}
}

/// Sets the channel priority to be used when solving environments
pub fn with_channel_priority(self, channel_priority: ChannelPriority) -> Self {
Self {
channel_priority,
..self
}
}

/// Construct a [`Configuration`] from the builder.
pub fn finish(self) -> Configuration {
let cache_dir = self.cache_dir.unwrap_or_else(|| {
Expand Down Expand Up @@ -317,6 +331,7 @@ impl ConfigurationBuilder {
compression_threads: self.compression_threads,
package_cache,
repodata_gateway,
channel_priority: self.channel_priority,
}
}
}

0 comments on commit 586982d

Please sign in to comment.