Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pubgrub to Ranges::from_iter #9145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ petgraph = { version = "0.6.5" }
platform-info = { version = "2.0.3" }
proc-macro2 = { version = "1.0.86" }
procfs = { version = "0.17.0", default-features = false, features = ["flate2"] }
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "95e1390399cdddee986b658be19587eb1fdb2d79" }
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "57afc831bf2551f164617a10383cf288bf5d190d" }
quote = { version = "1.0.37" }
rayon = { version = "1.10.0" }
reflink-copy = { version = "0.1.19" }
Expand Down Expand Up @@ -175,7 +175,7 @@ unicode-width = { version = "0.1.13" }
unscanny = { version = "0.1.0" }
url = { version = "2.5.2" }
urlencoding = { version = "2.1.3" }
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "95e1390399cdddee986b658be19587eb1fdb2d79" }
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "57afc831bf2551f164617a10383cf288bf5d190d" }
walkdir = { version = "2.5.0" }
which = { version = "7.0.0", features = ["regex"] }
windows-registry = { version = "0.3.0" }
Expand Down
39 changes: 20 additions & 19 deletions crates/uv-pep508/src/marker/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use std::ops::Bound;
use std::sync::Mutex;
use std::sync::MutexGuard;

use itertools::Either;
use itertools::{Either, Itertools};
use rustc_hash::FxHashMap;
use std::sync::LazyLock;
use uv_pep440::{release_specifier_to_range, Operator, Version, VersionSpecifier};
Expand Down Expand Up @@ -753,16 +753,15 @@ impl Edges {
///
/// Only for use when the `key` is a `PythonVersion`. Normalizes to `PythonFullVersion`.
fn from_python_versions(versions: Vec<Version>, negated: bool) -> Result<Edges, NodeId> {
let mut range = Ranges::empty();

// TODO(zanieb): We need to make sure this is performant, repeated unions like this do not
// seem efficient.
for version in versions {
let specifier = VersionSpecifier::equals_version(version.clone());
let specifier = python_version_to_full_version(specifier)?;
let pubgrub_specifier = release_specifier_to_range(normalize_specifier(specifier));
range = range.union(&pubgrub_specifier);
}
let mut range: Ranges<Version> = versions
.into_iter()
.map(|version| {
let specifier = VersionSpecifier::equals_version(version.clone());
let specifier = python_version_to_full_version(specifier)?;
Ok(release_specifier_to_range(normalize_specifier(specifier)))
})
.flatten_ok()
.collect::<Result<Ranges<_>, NodeId>>()?;

if negated {
range = range.complement();
Expand All @@ -774,14 +773,16 @@ impl Edges {
}

/// Returns an [`Edges`] where values in the given range are `true`.
fn from_versions(versions: &Vec<Version>, negated: bool) -> Edges {
let mut range = Ranges::empty();

// TODO(zanieb): We need to make sure this is performant, repeated unions like this do not
// seem efficient.
for version in versions {
range = range.union(&Ranges::singleton(version.clone()));
}
fn from_versions(versions: &[Version], negated: bool) -> Edges {
let mut range: Ranges<Version> = versions
.iter()
.map(|version| {
(
Bound::Included(version.clone()),
Bound::Included(version.clone()),
)
})
.collect();

if negated {
range = range.complement();
Expand Down
12 changes: 5 additions & 7 deletions crates/uv-resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,11 @@ impl<'range> SentinelRange<'range> {
}

/// Remove local versions sentinels (`+[max]`) from the version ranges.
pub fn strip(&self) -> Ranges<Version> {
let mut range = Ranges::empty();
for (lower, upper) in self.0.iter() {
let (lower, upper) = Self::strip_sentinel(lower.clone(), upper.clone());
range = range.union(&Range::from_range_bounds((lower, upper)));
}
range
pub fn strip(self) -> Ranges<Version> {
self.0
.iter()
.map(|(lower, upper)| Self::strip_sentinel(lower.clone(), upper.clone()))
.collect()
}

/// Remove local versions sentinels (`+[max]`) from the interval.
Expand Down
Loading