Skip to content

Commit

Permalink
chore: bump resolvo to 0.7.0 (#805)
Browse files Browse the repository at this point in the history
Bumps `resolvo` to 0.7.0.
  • Loading branch information
baszalmstra authored Aug 13, 2024
1 parent ea1bdc2 commit cc884ef
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ regex = "1.10.4"
reqwest = { version = "0.12.3", default-features = false }
reqwest-middleware = "0.3.0"
reqwest-retry = "0.6.0"
resolvo = { version = "0.6.1" }
resolvo = { version = "0.7.0" }
retry-policies = { version = "0.4.0", default-features = false }
rmp-serde = { version = "1.2.0" }
rstest = { version = "0.21.0" }
Expand Down
12 changes: 9 additions & 3 deletions crates/rattler_solve/src/resolvo/conda_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cmp::Ordering, collections::HashMap};

use futures::future::FutureExt;
use rattler_conda_types::Version;
use resolvo::{Dependencies, SolvableId, SolverCache, VersionSetId};
use resolvo::{Dependencies, Requirement, SolvableId, SolverCache, VersionSetId};

use crate::resolvo::CondaDependencyProvider;

Expand Down Expand Up @@ -89,14 +89,20 @@ pub(super) fn compare_candidates(
let a_match_specs = a_known
.requirements
.iter()
.map(|id| (*id, pool.resolve_version_set(*id)))
.filter_map(|req| match req {
Requirement::Single(id) => Some((*id, pool.resolve_version_set(*id))),
Requirement::Union(_) => None,
})
.map(|(spec_id, _)| (pool.resolve_version_set_package_name(spec_id), spec_id))
.collect::<HashMap<_, _>>();

let b_match_specs = b_known
.requirements
.iter()
.map(|id| (*id, pool.resolve_version_set(*id)))
.filter_map(|req| match req {
Requirement::Single(id) => Some((*id, pool.resolve_version_set(*id))),
Requirement::Union(_) => None,
})
.map(|(spec_id, _)| (pool.resolve_version_set_package_name(spec_id), spec_id))
.collect::<HashMap<_, _>>();
(a_match_specs, b_match_specs)
Expand Down
73 changes: 42 additions & 31 deletions crates/rattler_solve/src/resolvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use rattler_conda_types::{
};
use resolvo::{
utils::{Pool, VersionSet},
Candidates, Dependencies, DependencyProvider, Interner, KnownDependencies, NameId, SolvableId,
Solver as LibSolvRsSolver, SolverCache, StringId, UnsolvableOrCancelled, VersionSetId,
Candidates, Dependencies, DependencyProvider, Interner, KnownDependencies, NameId, Problem,
Requirement, SolvableId, Solver as LibSolvRsSolver, SolverCache, StringId,
UnsolvableOrCancelled, VersionSetId, VersionSetUnionId,
};

use crate::{
Expand Down Expand Up @@ -418,6 +419,28 @@ impl<'a> Interner for CondaDependencyProvider<'a> {
&self.pool.resolve_solvable(solvable).record
}

fn version_sets_in_union(
&self,
version_set_union: VersionSetUnionId,
) -> impl Iterator<Item = VersionSetId> {
self.pool.resolve_version_set_union(version_set_union)
}

fn display_merged_solvables(&self, solvables: &[SolvableId]) -> impl Display + '_ {
if solvables.is_empty() {
return String::new();
}

let versions = solvables
.iter()
.map(|&id| self.pool.resolve_solvable(id).record.version())
.sorted()
.format(" | ");

let name = self.display_solvable_name(solvables[0]);
format!("{name} {versions}")
}

fn display_name(&self, name: NameId) -> impl Display + '_ {
self.pool.resolve_package_name(name)
}
Expand All @@ -437,21 +460,6 @@ impl<'a> Interner for CondaDependencyProvider<'a> {
fn solvable_name(&self, solvable: SolvableId) -> NameId {
self.pool.resolve_solvable(solvable).name
}

fn display_merged_solvables(&self, solvables: &[SolvableId]) -> impl Display + '_ {
if solvables.is_empty() {
return String::new();
}

let versions = solvables
.iter()
.map(|&id| self.pool.resolve_solvable(id).record.version())
.sorted()
.format(" | ");

let name = self.display_solvable_name(solvables[0]);
format!("{name} {versions}")
}
}

impl<'a> DependencyProvider for CondaDependencyProvider<'a> {
Expand Down Expand Up @@ -505,7 +513,7 @@ impl<'a> DependencyProvider for CondaDependencyProvider<'a> {
return Dependencies::Unknown(reason);
}
};
dependencies.requirements.push(version_set_id);
dependencies.requirements.push(version_set_id.into());
}

for constrains in rec.package_record.constrains.iter() {
Expand Down Expand Up @@ -627,6 +635,7 @@ impl super::SolverImpl for Solver {

let all_requirements = virtual_package_requirements
.chain(root_requirements)
.map(Requirement::from)
.collect();

let root_constraints = task
Expand All @@ -640,22 +649,24 @@ impl super::SolverImpl for Solver {
})
.collect();

let problem = Problem {
requirements: all_requirements,
constraints: root_constraints,
..Problem::default()
};

// Construct a solver and solve the problems in the queue
let mut solver = LibSolvRsSolver::new(provider);
let solvables = solver.solve(all_requirements, root_constraints).map_err(
|unsolvable_or_cancelled| {
match unsolvable_or_cancelled {
UnsolvableOrCancelled::Unsolvable(problem) => {
SolveError::Unsolvable(vec![problem
.display_user_friendly(&solver)
.to_string()])
}
// We are not doing this as of yet
// put a generic message in here for now
UnsolvableOrCancelled::Cancelled(_) => SolveError::Cancelled,
let solvables = solver.solve(problem).map_err(|unsolvable_or_cancelled| {
match unsolvable_or_cancelled {
UnsolvableOrCancelled::Unsolvable(problem) => {
SolveError::Unsolvable(vec![problem.display_user_friendly(&solver).to_string()])
}
},
)?;
// We are not doing this as of yet
// put a generic message in here for now
UnsolvableOrCancelled::Cancelled(_) => SolveError::Cancelled,
}
})?;

// Get the resulting packages from the solver.
let required_records = solvables
Expand Down
4 changes: 2 additions & 2 deletions py-rattler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc884ef

Please sign in to comment.