From 78004ba66fa18dfb10aa5755ec757fb437ce392b Mon Sep 17 00:00:00 2001 From: Zanie Date: Thu, 25 Jan 2024 18:34:23 -0600 Subject: [PATCH] Order insertions into the available versions map --- crates/pep508-rs/src/verbatim_url.rs | 5 +++-- crates/puffin-resolver/src/error.rs | 9 +++++---- crates/puffin-resolver/src/pubgrub/package.rs | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/pep508-rs/src/verbatim_url.rs b/crates/pep508-rs/src/verbatim_url.rs index 74494b134..46bbf71f1 100644 --- a/crates/pep508-rs/src/verbatim_url.rs +++ b/crates/pep508-rs/src/verbatim_url.rs @@ -8,8 +8,8 @@ use regex::Regex; use url::Url; /// A wrapper around [`Url`] that preserves the original string. -#[derive(Debug, Clone, Eq, derivative::Derivative)] -#[derivative(PartialEq, Hash)] +#[derive(Debug, Clone, Eq, Ord, derivative::Derivative)] +#[derivative(PartialEq, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct VerbatimUrl { /// The parsed URL. @@ -22,6 +22,7 @@ pub struct VerbatimUrl { )] url: Url, /// The URL as it was provided by the user. + #[derivative(PartialOrd = "ignore")] #[derivative(PartialEq = "ignore")] #[derivative(Hash = "ignore")] given: Option, diff --git a/crates/puffin-resolver/src/error.rs b/crates/puffin-resolver/src/error.rs index c84a3181d..b30a7dd2e 100644 --- a/crates/puffin-resolver/src/error.rs +++ b/crates/puffin-resolver/src/error.rs @@ -3,6 +3,7 @@ use std::convert::Infallible; use std::fmt::Formatter; use indexmap::IndexMap; +use itertools::Itertools; use pubgrub::range::Range; use pubgrub::report::{DefaultStringReporter, DerivationTree, Reporter}; use url::Url; @@ -170,18 +171,18 @@ impl NoSolutionError { package_versions: &OnceMap, ) -> Self { let mut available_versions = IndexMap::default(); - for package in self.derivation_tree.packages() { + for package in self.derivation_tree.packages().iter().sorted() { match package { PubGrubPackage::Root(_) => {} PubGrubPackage::Python(PubGrubPython::Installed) => { available_versions.insert( - package.clone(), + (*package).clone(), BTreeSet::from([python_requirement.installed().clone()]), ); } PubGrubPackage::Python(PubGrubPython::Target) => { available_versions.insert( - package.clone(), + (*package).clone(), BTreeSet::from([python_requirement.target().clone()]), ); } @@ -189,7 +190,7 @@ impl NoSolutionError { if let Some(entry) = package_versions.get(name) { let version_map = entry.value(); available_versions.insert( - package.clone(), + (*package).clone(), version_map .iter() .map(|(version, _)| version.clone()) diff --git a/crates/puffin-resolver/src/pubgrub/package.rs b/crates/puffin-resolver/src/pubgrub/package.rs index 555489587..130327fcf 100644 --- a/crates/puffin-resolver/src/pubgrub/package.rs +++ b/crates/puffin-resolver/src/pubgrub/package.rs @@ -10,7 +10,7 @@ use puffin_normalize::{ExtraName, PackageName}; /// 2. Uses the same strategy as pip and posy to handle extras: for each extra, we create a virtual /// package (e.g., `black[colorama]`), and mark it as a dependency of the real package (e.g., /// `black`). We then discard the virtual packages at the end of the resolution process. -#[derive(Debug, Clone, Eq, Derivative)] +#[derive(Debug, Clone, Eq, Derivative, PartialOrd, Ord)] #[derivative(PartialEq, Hash)] pub enum PubGrubPackage { /// The root package, which is used to start the resolution process. @@ -74,7 +74,7 @@ pub enum PubGrubPackage { ), } -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum PubGrubPython { /// The Python version installed in the current environment. Installed,