Skip to content

Commit

Permalink
feat: implement --no-deps and --only-deps (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Feb 14, 2025
1 parent 5938673 commit 6c288be
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use rattler::{
package_cache::PackageCache,
};
use rattler_conda_types::{
Channel, ChannelConfig, GenericVirtualPackage, MatchSpec, PackageName, ParseStrictness,
Platform, PrefixRecord, RepoDataRecord, Version,
Channel, ChannelConfig, GenericVirtualPackage, MatchSpec, Matches, PackageName,
ParseStrictness, Platform, PrefixRecord, RepoDataRecord, Version,
};
use rattler_networking::{AuthenticationMiddleware, AuthenticationStorage};
use rattler_repodata_gateway::{Gateway, RepoData, SourceConfig};
Expand Down Expand Up @@ -60,6 +60,12 @@ pub struct Opt {

#[clap(long)]
strategy: Option<SolveStrategy>,

#[clap(long, group = "deps_mode")]
only_deps: bool,

#[clap(long, group = "deps_mode")]
no_deps: bool,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
Expand Down Expand Up @@ -254,7 +260,7 @@ pub async fn create(opt: Opt) -> anyhow::Result<()> {
let solver_task = SolverTask {
locked_packages,
virtual_packages,
specs,
specs: specs.clone(),
timeout: opt.timeout.map(Duration::from_millis),
strategy: opt.strategy.map_or_else(Default::default, Into::into),
..SolverTask::from_iter(&repo_data)
Expand All @@ -269,7 +275,13 @@ pub async fn create(opt: Opt) -> anyhow::Result<()> {
Solver::LibSolv => libsolv_c::Solver.solve(solver_task),
})?;

let required_packages: Vec<RepoDataRecord> = solver_result.records;
let mut required_packages: Vec<RepoDataRecord> = solver_result.records;

if opt.no_deps {
required_packages.retain(|r| specs.iter().any(|s| s.matches(&r.package_record)));
} else if opt.only_deps {
required_packages.retain(|r| !specs.iter().any(|s| s.matches(&r.package_record)));
};

if opt.dry_run {
// Construct a transaction to
Expand Down

0 comments on commit 6c288be

Please sign in to comment.