Skip to content

Commit e434f41

Browse files
committed
Fix dependency group handling
1 parent 9cb49cb commit e434f41

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

crates/uv-resolver/src/pubgrub/package.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ impl PubGrubPackage {
133133
}
134134
}
135135

136+
/// If this package is a proxy package, return the base package it depends on.
137+
///
138+
/// While dependency groups may be attached to a package, we don't consider them here as
139+
/// there is no (mandatory) dependency from a dependency group to the package.
140+
pub(crate) fn base_package(&self) -> Option<Self> {
141+
match &**self {
142+
PubGrubPackageInner::Root(_)
143+
| PubGrubPackageInner::Python(_)
144+
| PubGrubPackageInner::System(_)
145+
| PubGrubPackageInner::Package { .. } => None,
146+
PubGrubPackageInner::Group { .. } => {
147+
// The dependency groups of a package do not by themselves require the package
148+
// itself.
149+
None
150+
}
151+
PubGrubPackageInner::Extra { name, .. } | PubGrubPackageInner::Marker { name, .. } => {
152+
Some(Self::from_package(
153+
name.clone(),
154+
None,
155+
None,
156+
MarkerTree::TRUE,
157+
))
158+
}
159+
}
160+
}
161+
136162
/// Returns the name of this PubGrub package, if it has one.
137163
pub(crate) fn name(&self) -> Option<&PackageName> {
138164
match &**self {

crates/uv-resolver/src/pubgrub/priority.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ impl PubGrubPriorities {
151151
let package_tiebreaker = match self.virtual_package_tiebreaker.get(package) {
152152
Some(tiebreaker) => *tiebreaker,
153153
None => {
154-
//if cfg!(debug_assertions) {
155-
// panic!("Virtual package not known: `{package}`")
156-
//} else {
157-
PubGrubTiebreaker(Reverse(u32::MAX))
158-
//}
154+
if cfg!(debug_assertions) {
155+
panic!("Package not registered in prioritization: `{package:?}`")
156+
} else {
157+
PubGrubTiebreaker(Reverse(u32::MAX))
158+
}
159159
}
160160
};
161161

crates/uv-resolver/src/resolver/mod.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,12 @@ impl ForkState {
28662866

28672867
// Update the package priorities.
28682868
self.priorities.insert(package, version, &self.fork_urls);
2869+
// As we're adding an incompatibility from the proxy package to the base package,
2870+
// we need to register the base package.
2871+
if let Some(base_package) = package.base_package() {
2872+
self.priorities
2873+
.insert(&base_package, version, &self.fork_urls);
2874+
}
28692875
}
28702876

28712877
Ok(())
@@ -2886,20 +2892,8 @@ impl ForkState {
28862892
url: _,
28872893
} = dependency;
28882894

2889-
let base_package = match &**package {
2890-
PubGrubPackageInner::Root(_)
2891-
| PubGrubPackageInner::Python(_)
2892-
| PubGrubPackageInner::System(_)
2893-
| PubGrubPackageInner::Package { .. } => continue,
2894-
PubGrubPackageInner::Dev { .. } => {
2895-
// The dependency groups of a package do not by themselves require the package
2896-
// itself.
2897-
continue;
2898-
}
2899-
PubGrubPackageInner::Extra { name, .. }
2900-
| PubGrubPackageInner::Marker { name, .. } => {
2901-
PubGrubPackage::from_package(name.clone(), None, None, MarkerTree::TRUE)
2902-
}
2895+
let Some(base_package) = package.base_package() else {
2896+
continue;
29032897
};
29042898

29052899
let proxy_package = self.pubgrub.package_store.alloc(package.clone());

0 commit comments

Comments
 (0)