mirror of https://github.com/astral-sh/uv
Layer on our changes
This commit is contained in:
parent
c4e108136d
commit
6bb6923ef4
|
|
@ -1,6 +1,6 @@
|
||||||
|
use fxhash::FxHashMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use pubgrub::range::Range;
|
use pubgrub::range::Range;
|
||||||
use pubgrub::type_aliases::DependencyConstraints;
|
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use pep508_rs::{MarkerEnvironment, Requirement, VersionOrUrl};
|
use pep508_rs::{MarkerEnvironment, Requirement, VersionOrUrl};
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::pubgrub::{PubGrubPackage, PubGrubVersion};
|
||||||
use crate::ResolveError;
|
use crate::ResolveError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PubGrubDependencies(DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>>);
|
pub struct PubGrubDependencies(FxHashMap<PubGrubPackage, Range<PubGrubVersion>>);
|
||||||
|
|
||||||
impl PubGrubDependencies {
|
impl PubGrubDependencies {
|
||||||
/// Generate a set of `PubGrub` dependencies from a set of requirements.
|
/// Generate a set of `PubGrub` dependencies from a set of requirements.
|
||||||
|
|
@ -23,8 +23,7 @@ impl PubGrubDependencies {
|
||||||
source: Option<&'a PackageName>,
|
source: Option<&'a PackageName>,
|
||||||
env: &'a MarkerEnvironment,
|
env: &'a MarkerEnvironment,
|
||||||
) -> Result<Self, ResolveError> {
|
) -> Result<Self, ResolveError> {
|
||||||
let mut dependencies =
|
let mut dependencies = FxHashMap::<PubGrubPackage, Range<PubGrubVersion>>::default();
|
||||||
DependencyConstraints::<PubGrubPackage, Range<PubGrubVersion>>::default();
|
|
||||||
|
|
||||||
// Iterate over all declared requirements.
|
// Iterate over all declared requirements.
|
||||||
for requirement in requirements {
|
for requirement in requirements {
|
||||||
|
|
@ -138,7 +137,7 @@ impl PubGrubDependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a [`PubGrubDependencies`] to a [`DependencyConstraints`].
|
/// Convert a [`PubGrubDependencies`] to a [`DependencyConstraints`].
|
||||||
impl From<PubGrubDependencies> for DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>> {
|
impl From<PubGrubDependencies> for FxHashMap<PubGrubPackage, Range<PubGrubVersion>> {
|
||||||
fn from(dependencies: PubGrubDependencies) -> Self {
|
fn from(dependencies: PubGrubDependencies) -> Self {
|
||||||
dependencies.0
|
dependencies.0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ use fxhash::{FxHashMap, FxHashSet};
|
||||||
use pubgrub::error::PubGrubError;
|
use pubgrub::error::PubGrubError;
|
||||||
use pubgrub::range::Range;
|
use pubgrub::range::Range;
|
||||||
use pubgrub::solver::{Incompatibility, State};
|
use pubgrub::solver::{Incompatibility, State};
|
||||||
use pubgrub::type_aliases::DependencyConstraints;
|
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error, trace};
|
||||||
|
|
@ -236,7 +235,12 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
|
||||||
));
|
));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Dependencies::Known(constraints) if constraints.contains_key(package) => {
|
Dependencies::Known(constraints)
|
||||||
|
if constraints
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.any(|(dependency, _)| &dependency == package) =>
|
||||||
|
{
|
||||||
return Err(PubGrubError::SelfDependency {
|
return Err(PubGrubError::SelfDependency {
|
||||||
package: package.clone(),
|
package: package.clone(),
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
|
|
@ -250,7 +254,7 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
|
||||||
let dep_incompats = state.add_incompatibility_from_dependencies(
|
let dep_incompats = state.add_incompatibility_from_dependencies(
|
||||||
package.clone(),
|
package.clone(),
|
||||||
version.clone(),
|
version.clone(),
|
||||||
&dependencies,
|
dependencies,
|
||||||
);
|
);
|
||||||
|
|
||||||
state.partial_solution.add_version(
|
state.partial_solution.add_version(
|
||||||
|
|
@ -977,5 +981,5 @@ enum Dependencies {
|
||||||
/// Package dependencies are unavailable.
|
/// Package dependencies are unavailable.
|
||||||
Unknown,
|
Unknown,
|
||||||
/// Container for all available package versions.
|
/// Container for all available package versions.
|
||||||
Known(DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>>),
|
Known(FxHashMap<PubGrubPackage, Range<PubGrubVersion>>),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.73"
|
channel = "nightly"
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub struct State<P: Package, VS: VersionSet, Priority: Ord + Clone> {
|
||||||
root_package: P,
|
root_package: P,
|
||||||
root_version: VS::V,
|
root_version: VS::V,
|
||||||
|
|
||||||
incompatibilities: Map<P, Vec<IncompId<P, VS>>>,
|
pub incompatibilities: Map<P, Vec<IncompId<P, VS>>>,
|
||||||
|
|
||||||
/// Store the ids of incompatibilities that are already contradicted
|
/// Store the ids of incompatibilities that are already contradicted
|
||||||
/// and will stay that way until the next conflict and backtrack is operated.
|
/// and will stay that way until the next conflict and backtrack is operated.
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,14 @@ use crate::version_set::VersionSet;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Incompatibility<P: Package, VS: VersionSet> {
|
pub struct Incompatibility<P: Package, VS: VersionSet> {
|
||||||
package_terms: SmallMap<P, Term<VS>>,
|
package_terms: SmallMap<P, Term<VS>>,
|
||||||
kind: Kind<P, VS>,
|
pub kind: Kind<P, VS>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type alias of unique identifiers for incompatibilities.
|
/// Type alias of unique identifiers for incompatibilities.
|
||||||
pub type IncompId<P, VS> = Id<Incompatibility<P, VS>>;
|
pub type IncompId<P, VS> = Id<Incompatibility<P, VS>>;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Kind<P: Package, VS: VersionSet> {
|
pub enum Kind<P: Package, VS: VersionSet> {
|
||||||
/// Initial incompatibility aiming at picking the root package for the first decision.
|
/// Initial incompatibility aiming at picking the root package for the first decision.
|
||||||
NotRoot(P, VS::V),
|
NotRoot(P, VS::V),
|
||||||
/// There are no versions in the given range for this package.
|
/// There are no versions in the given range for this package.
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,24 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prioritized_packages(&self) -> impl Iterator<Item = (&P, &VS)> {
|
||||||
|
let check_all = self.changed_this_decision_level
|
||||||
|
== self.current_decision_level.0.saturating_sub(1) as usize;
|
||||||
|
let current_decision_level = self.current_decision_level;
|
||||||
|
self.package_assignments
|
||||||
|
.get_range(self.changed_this_decision_level..)
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(move |(_, pa)| {
|
||||||
|
// We only actually need to update the package if its Been changed
|
||||||
|
// since the last time we called prioritize.
|
||||||
|
// Which means it's highest decision level is the current decision level,
|
||||||
|
// or if we backtracked in the mean time.
|
||||||
|
check_all || pa.highest_decision_level == current_decision_level
|
||||||
|
})
|
||||||
|
.filter_map(|(p, pa)| pa.assignments_intersection.potential_package_filter(p))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pick_highest_priority_pkg(
|
pub fn pick_highest_priority_pkg(
|
||||||
&mut self,
|
&mut self,
|
||||||
prioritizer: impl Fn(&P, &VS) -> Priority,
|
prioritizer: impl Fn(&P, &VS) -> Priority,
|
||||||
|
|
|
||||||
|
|
@ -219,8 +219,7 @@
|
||||||
//! with a cache, you may want to know that some versions
|
//! with a cache, you may want to know that some versions
|
||||||
//! do not exist in your cache.
|
//! do not exist in your cache.
|
||||||
|
|
||||||
#![allow(clippy::rc_buffer)]
|
#![allow(clippy::all, unreachable_pub)]
|
||||||
#![warn(missing_docs)]
|
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod package;
|
pub mod package;
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,7 @@ impl<V: Display + Eq> Display for Range<V> {
|
||||||
(Included(v), Unbounded) => write!(f, ">={v}")?,
|
(Included(v), Unbounded) => write!(f, ">={v}")?,
|
||||||
(Included(v), Included(b)) => {
|
(Included(v), Included(b)) => {
|
||||||
if v == b {
|
if v == b {
|
||||||
write!(f, "{v}")?
|
write!(f, "=={v}")?
|
||||||
} else {
|
} else {
|
||||||
write!(f, ">={v}, <={b}")?
|
write!(f, ">={v}, <={b}")?
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ use std::collections::{BTreeMap, BTreeSet as Set};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use crate::error::PubGrubError;
|
use crate::error::PubGrubError;
|
||||||
use crate::internal::core::State;
|
pub use crate::internal::core::State;
|
||||||
use crate::internal::incompatibility::Incompatibility;
|
pub use crate::internal::incompatibility::{Incompatibility, Kind};
|
||||||
use crate::package::Package;
|
use crate::package::Package;
|
||||||
use crate::type_aliases::{Map, SelectedDependencies};
|
use crate::type_aliases::{Map, SelectedDependencies};
|
||||||
use crate::version_set::VersionSet;
|
use crate::version_set::VersionSet;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ impl<VS: VersionSet> Term<VS> {
|
||||||
|
|
||||||
/// Unwrap the set contained in a positive term.
|
/// Unwrap the set contained in a positive term.
|
||||||
/// Will panic if used on a negative set.
|
/// Will panic if used on a negative set.
|
||||||
pub(crate) fn unwrap_positive(&self) -> &VS {
|
pub fn unwrap_positive(&self) -> &VS {
|
||||||
match self {
|
match self {
|
||||||
Self::Positive(set) => set,
|
Self::Positive(set) => set,
|
||||||
_ => panic!("Negative term cannot unwrap positive set"),
|
_ => panic!("Negative term cannot unwrap positive set"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue