Order insertions into the available versions map

This commit is contained in:
Zanie 2024-01-25 18:34:23 -06:00
parent 0cdde8949f
commit 78004ba66f
3 changed files with 10 additions and 8 deletions

View File

@ -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<String>,

View File

@ -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<PackageName, VersionMap>,
) -> 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())

View File

@ -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,