Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
185 changes: 111 additions & 74 deletions crates/uv-pypi-types/src/conflicts.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/uv-resolver/src/graph_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(crate) fn simplify_conflict_markers(
let mut new_set = FxHashSet::default();
for item in set {
for conflict_set in conflicts.iter() {
if !conflict_set.contains(item.package(), item.as_ref().conflict()) {
if !conflict_set.contains(item.package(), item.as_ref().kind()) {
continue;
}
for conflict_item in conflict_set.iter() {
Expand Down
5 changes: 5 additions & 0 deletions crates/uv-resolver/src/lock/installable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub trait Installable<'lock> {

let mut queue: VecDeque<(&Package, Option<&ExtraName>)> = VecDeque::new();
let mut seen = FxHashSet::default();
let mut activated_projects: Vec<&PackageName> = vec![];
let mut activated_extras: Vec<(&PackageName, &ExtraName)> = vec![];
let mut activated_groups: Vec<(&PackageName, &GroupName)> = vec![];

Expand All @@ -74,6 +75,7 @@ pub trait Installable<'lock> {

// Track the activated extras.
if dev.prod() {
activated_projects.push(&dist.id.name);
for extra in extras.extra_names(dist.optional_dependencies.keys()) {
activated_extras.push((&dist.id.name, extra));
}
Expand Down Expand Up @@ -143,6 +145,7 @@ pub trait Installable<'lock> {
{
if !dep.complexified_marker.evaluate(
marker_env,
activated_projects.iter().copied(),
activated_extras.iter().copied(),
activated_groups.iter().copied(),
) {
Expand Down Expand Up @@ -367,6 +370,7 @@ pub trait Installable<'lock> {
}
if !dep.complexified_marker.evaluate(
marker_env,
activated_projects.iter().copied(),
activated_extras
.iter()
.chain(additional_activated_extras.iter())
Expand Down Expand Up @@ -454,6 +458,7 @@ pub trait Installable<'lock> {
for dep in deps {
if !dep.complexified_marker.evaluate(
marker_env,
activated_projects.iter().copied(),
activated_extras.iter().copied(),
activated_groups.iter().copied(),
) {
Expand Down
36 changes: 31 additions & 5 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use uv_platform_tags::{
AbiTag, IncompatibleTag, LanguageTag, PlatformTag, TagCompatibility, TagPriority, Tags,
};
use uv_pypi_types::{
ConflictPackage, Conflicts, HashAlgorithm, HashDigest, HashDigests, Hashes, ParsedArchiveUrl,
ConflictKind, Conflicts, HashAlgorithm, HashDigest, HashDigests, Hashes, ParsedArchiveUrl,
ParsedGitUrl,
};
use uv_redacted::DisplaySafeUrl;
Expand Down Expand Up @@ -852,11 +852,12 @@ impl Lock {
list.push(each_element_on_its_line_array(set.iter().map(|item| {
let mut table = InlineTable::new();
table.insert("package", Value::from(item.package().to_string()));
match item.conflict() {
ConflictPackage::Extra(extra) => {
match item.kind() {
ConflictKind::Project => {}
ConflictKind::Extra(extra) => {
table.insert("extra", Value::from(extra.to_string()));
}
ConflictPackage::Group(group) => {
ConflictKind::Group(group) => {
table.insert("group", Value::from(group.to_string()));
}
}
Expand Down Expand Up @@ -2871,6 +2872,21 @@ impl Package {
pub fn dependency_groups(&self) -> &BTreeMap<GroupName, BTreeSet<Requirement>> {
&self.metadata.dependency_groups
}

/// Returns the dependencies of the package.
pub fn dependencies(&self) -> &[Dependency] {
&self.dependencies
}

/// Returns the optional dependencies of the package.
pub fn optional_dependencies(&self) -> &BTreeMap<ExtraName, Vec<Dependency>> {
&self.optional_dependencies
}

/// Returns the resolved PEP 735 dependency groups of the package.
pub fn resolved_dependency_groups(&self) -> &BTreeMap<GroupName, Vec<Dependency>> {
&self.dependency_groups
}
}

/// Attempts to construct a `VerbatimUrl` from the given normalized `Path`.
Expand Down Expand Up @@ -4453,7 +4469,7 @@ impl TryFrom<WheelWire> for Wheel {

/// A single dependency of a package in a lockfile.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
struct Dependency {
pub struct Dependency {
package_id: PackageId,
extra: BTreeSet<ExtraName>,
/// A marker simplified from the PEP 508 marker in `complexified_marker`
Expand Down Expand Up @@ -4538,6 +4554,16 @@ impl Dependency {

table
}

/// Returns the package name of this dependency.
pub fn package_name(&self) -> &PackageName {
&self.package_id.name
}

/// Returns the extras specified on this dependency.
pub fn extra(&self) -> &BTreeSet<ExtraName> {
&self.extra
}
}

impl Display for Dependency {
Expand Down
64 changes: 53 additions & 11 deletions crates/uv-resolver/src/pubgrub/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use uv_distribution_types::{Requirement, RequirementSource};
use uv_normalize::{ExtraName, GroupName, PackageName};
use uv_pep440::{Version, VersionSpecifiers};
use uv_pypi_types::{
Conflicts, ParsedArchiveUrl, ParsedDirectoryUrl, ParsedGitUrl, ParsedPathUrl, ParsedUrl,
VerbatimParsedUrl,
ConflictItemRef, Conflicts, ParsedArchiveUrl, ParsedDirectoryUrl, ParsedGitUrl, ParsedPathUrl,
ParsedUrl, VerbatimParsedUrl,
};

use crate::pubgrub::{PubGrubPackage, PubGrubPackageInner};
Expand All @@ -19,6 +19,21 @@ pub(crate) struct PubGrubDependency {
pub(crate) package: PubGrubPackage,
pub(crate) version: Ranges<Version>,

/// When the parent that created this dependency is a "normal" package
/// (non-extra non-group), this corresponds to its name.
///
/// This is used to create project-level `ConflictItemRef` for a specific
/// package. In effect, this lets us "delay" filtering of project
/// dependencies when a conflict is declared between the project and a
/// group.
///
/// The main problem with deal with project level conflicts is that if you
/// declare a conflict between a package and a group, we represent that
/// group as a dependency of that package. So if you filter out the package
/// in a fork due to a conflict, you also filter out the group. Therefore,
/// we introduce this parent field to enable "delayed" filtering.
pub(crate) parent: Option<PackageName>,

/// This field is set if the [`Requirement`] had a URL. We still use a URL from [`Urls`]
/// even if this field is None where there is an override with a URL or there is a different
/// requirement or constraint for the same package that has a URL.
Expand All @@ -30,8 +45,12 @@ impl PubGrubDependency {
conflicts: &Conflicts,
requirement: Cow<'a, Requirement>,
dev: Option<&'a GroupName>,
source_name: Option<&'a PackageName>,
parent_package: Option<&'a PubGrubPackage>,
) -> impl Iterator<Item = Self> + 'a {
let parent_name = parent_package.and_then(|package| package.name_no_root());
let is_normal_parent = parent_package
.map(|pp| pp.extra().is_none() && pp.dev().is_none())
.unwrap_or(false);
let iter = if !requirement.extras.is_empty() {
// This is crazy subtle, but if any of the extras in the
// requirement are part of a declared conflict, then we
Expand Down Expand Up @@ -80,50 +99,59 @@ impl PubGrubDependency {

// Add the package, plus any extra variants.
iter.map(move |(extra, group)| {
PubGrubRequirement::from_requirement(&requirement, extra, group)
})
.map(move |requirement| {
let pubgrub_requirement =
PubGrubRequirement::from_requirement(&requirement, extra, group);
let PubGrubRequirement {
package,
version,
url,
} = requirement;
} = pubgrub_requirement;
match &*package {
PubGrubPackageInner::Package { .. } => PubGrubDependency {
package,
version,
parent: if is_normal_parent {
parent_name.cloned()
} else {
None
},
url,
},
PubGrubPackageInner::Marker { .. } => PubGrubDependency {
package,
version,
parent: if is_normal_parent {
parent_name.cloned()
} else {
None
},
url,
},
PubGrubPackageInner::Extra { name, .. } => {
// Detect self-dependencies.
if dev.is_none() {
debug_assert!(
source_name.is_none_or(|source_name| source_name != name),
parent_name.is_none_or(|parent_name| parent_name != name),
"extras not flattened for {name}"
);
}
PubGrubDependency {
package,
version,
parent: None,
url,
}
}
PubGrubPackageInner::Dev { name, .. } => {
// Detect self-dependencies.
if dev.is_none() {
debug_assert!(
source_name.is_none_or(|source_name| source_name != name),
parent_name.is_none_or(|parent_name| parent_name != name),
"group not flattened for {name}"
);
}
PubGrubDependency {
package,
version,
parent: None,
url,
}
}
Expand All @@ -135,6 +163,20 @@ impl PubGrubDependency {
}
})
}

/// Extracts a possible conflicting item from this dependency.
///
/// If this package can't possibly be classified as conflicting, then this
/// returns `None`.
pub(crate) fn conflicting_item(&self) -> Option<ConflictItemRef<'_>> {
if let Some(conflict) = self.package.conflicting_item() {
return Some(conflict);
}
if let Some(ref parent) = self.parent {
return Some(ConflictItemRef::from(parent));
}
None
}
}

/// A PubGrub-compatible package and version range.
Expand Down
8 changes: 4 additions & 4 deletions crates/uv-resolver/src/pubgrub/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ impl PubGrubPackage {
}
}

/// Extracts a possible conflicting group from this package.
/// Extracts a possible conflicting item from this package.
///
/// If this package can't possibly be classified as a conflicting group,
/// then this returns `None`.
/// If this package can't possibly be classified as conflicting, then
/// this returns `None`.
pub(crate) fn conflicting_item(&self) -> Option<ConflictItemRef<'_>> {
let package = self.name_no_root()?;
match (self.extra(), self.dev()) {
(None, None) => None,
(None, None) => Some(ConflictItemRef::from(package)),
(Some(extra), None) => Some(ConflictItemRef::from((package, extra))),
(None, Some(group)) => Some(ConflictItemRef::from((package, group))),
(Some(extra), Some(group)) => {
Expand Down
Loading