Skip to content

Commit

Permalink
wip: async support
Browse files Browse the repository at this point in the history
  • Loading branch information
aochagavia committed Feb 2, 2024
1 parent dc50a6b commit 8c1a216
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ consolidate-commits = true
tag-prefix = ""

[patch.crates-io]
resolvo = { git = "https://github.com/aochagavia/resolvo.git", branch = "concurrent-metadata-fetching" }
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::rc::Rc;
use std::str::FromStr;
use std::sync::Arc;
use thiserror::Error;
Expand Down Expand Up @@ -201,7 +202,7 @@ impl Display for PypiPackageName {

/// This is a [`DependencyProvider`] for PyPI packages
pub(crate) struct PypiDependencyProvider {
pub pool: Pool<PypiVersionSet, PypiPackageName>,
pub pool: Rc<Pool<PypiVersionSet, PypiPackageName>>,
package_db: Arc<PackageDb>,
wheel_builder: Arc<WheelBuilder>,
markers: Arc<MarkerEnvironment>,
Expand Down Expand Up @@ -244,7 +245,7 @@ impl PypiDependencyProvider {
);

Ok(Self {
pool,
pool: Rc::new(pool),
package_db,
wheel_builder,
markers,
Expand Down Expand Up @@ -400,8 +401,8 @@ pub(crate) enum MetadataError {
}

impl<'p> DependencyProvider<PypiVersionSet, PypiPackageName> for &'p PypiDependencyProvider {
fn pool(&self) -> &Pool<PypiVersionSet, PypiPackageName> {
&self.pool
fn pool(&self) -> Rc<Pool<PypiVersionSet, PypiPackageName>> {
self.pool.clone()
}

fn should_cancel_with_value(&self) -> Option<Box<dyn Any>> {
Expand All @@ -414,7 +415,7 @@ impl<'p> DependencyProvider<PypiVersionSet, PypiPackageName> for &'p PypiDepende

fn sort_candidates(
&self,
solver: &SolverCache<PypiVersionSet, PypiPackageName, Self>,
_: &SolverCache<PypiVersionSet, PypiPackageName, Self>,
solvables: &mut [SolvableId],
) {
solvables.sort_by(|&a, &b| {
Expand All @@ -439,8 +440,8 @@ impl<'p> DependencyProvider<PypiVersionSet, PypiPackageName> for &'p PypiDepende
}
}

let solvable_a = solver.pool().resolve_solvable(a);
let solvable_b = solver.pool().resolve_solvable(b);
let solvable_a = self.pool.resolve_solvable(a);
let solvable_b = self.pool.resolve_solvable(b);

match (&solvable_a.inner(), &solvable_b.inner()) {
// Sort Urls alphabetically
Expand All @@ -460,7 +461,7 @@ impl<'p> DependencyProvider<PypiVersionSet, PypiPackageName> for &'p PypiDepende
})
}

fn get_candidates(&self, name: NameId) -> Option<Candidates> {
async fn get_candidates(&self, name: NameId) -> Option<Candidates> {
let package_name = self.pool.resolve_package_name(name);
tracing::info!("collecting {}", package_name);

Expand Down Expand Up @@ -600,7 +601,7 @@ impl<'p> DependencyProvider<PypiVersionSet, PypiPackageName> for &'p PypiDepende
Some(candidates)
}

fn get_dependencies(&self, solvable_id: SolvableId) -> Dependencies {
async fn get_dependencies(&self, solvable_id: SolvableId) -> Dependencies {
let solvable = self.pool.resolve_solvable(solvable_id);
let package_name = self.pool.resolve_package_name(solvable.name_id());
let package_version = solvable.inner();
Expand Down
13 changes: 8 additions & 5 deletions crates/rattler_installs_packages/src/resolve/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,19 @@ pub async fn resolve(
)?;

// Invoke the solver to get a solution to the requirements
let mut solver = Solver::new(&provider);
let mut solver = Solver::new_with_default_runtime(&provider);
let solvables = match solver.solve(root_requirements) {
Ok(solvables) => solvables,
Err(e) => {
return match e {
UnsolvableOrCancelled::Unsolvable(problem) => Err(miette::miette!(
"{}",
problem
.display_user_friendly(&solver, &DefaultSolvableDisplay)
.display_user_friendly(
&solver,
solver.pool.clone(),
&DefaultSolvableDisplay
)
.to_string()
.trim()
)),
Expand All @@ -345,9 +349,8 @@ pub async fn resolve(
};
let mut result: HashMap<NormalizedPackageName, PinnedPackage> = HashMap::new();
for solvable_id in solvables {
let pool = solver.pool();
let solvable = pool.resolve_solvable(solvable_id);
let name = pool.resolve_package_name(solvable.name_id());
let solvable = solver.pool.resolve_solvable(solvable_id);
let name = solver.pool.resolve_package_name(solvable.name_id());
let version = solvable.inner();

let artifacts: Vec<_> = provider
Expand Down

0 comments on commit 8c1a216

Please sign in to comment.