Skip to content

Commit

Permalink
Use a custom UnavailablePackage variant for workspace members inste…
Browse files Browse the repository at this point in the history
…ad of `NoVersions`
  • Loading branch information
zanieb committed Aug 15, 2024
1 parent 6196bfa commit f0de4f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/pubgrub/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl PubGrubReportFormatter<'_> {
reason: reason.clone(),
});
}
Some(UnavailablePackage::NotFound) => {}
Some(UnavailablePackage::NotFound | UnavailablePackage::WorkspaceMember) => {}
None => {}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/uv-resolver/src/resolver/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub(crate) enum UnavailablePackage {
InvalidMetadata(String),
/// The package has an invalid structure.
InvalidStructure(String),
/// No other versions of the package can be used because it is a workspace member
WorkspaceMember,
}

impl UnavailablePackage {
Expand All @@ -85,6 +87,7 @@ impl UnavailablePackage {
UnavailablePackage::MissingMetadata => "does not include a `METADATA` file",
UnavailablePackage::InvalidMetadata(_) => "has invalid metadata",
UnavailablePackage::InvalidStructure(_) => "has an invalid package format",
UnavailablePackage::WorkspaceMember => "is a workspace member",
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,23 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.term_intersection_for_package(&state.next)
.expect("a package was chosen but we don't have a term");

// Check if the decision was due to the package being unavailable
if let PubGrubPackageInner::Package { ref name, .. } = &*state.next {
// Check if the decision was due to the package being a
// workspace member
if self.workspace_members.contains(name) {
state
.pubgrub
.add_incompatibility(Incompatibility::custom_term(
state.next.clone(),
term_intersection.clone(),
UnavailableReason::Package(
UnavailablePackage::WorkspaceMember,
),
));
continue;
}

// Check if the decision was due to the package being unavailable
if let Some(entry) = self.unavailable_packages.get(name) {
state
.pubgrub
Expand Down
10 changes: 5 additions & 5 deletions crates/uv/tests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ fn workspace_unsatisfiable_member_dependencies() -> Result<()> {
Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
× No solution found when resolving dependencies:
╰─▶ Because only httpx<=9999 is available and leaf==0.1.0 depends on httpx>9999, we can conclude that leaf==0.1.0 cannot be used.
And because only leaf==0.1.0 is available and you require leaf, we can conclude that the requirements are unsatisfiable.
And because leaf is a workspace member and you require leaf, we can conclude that the requirements are unsatisfiable.
"###
);

Expand Down Expand Up @@ -1256,8 +1256,8 @@ fn workspace_unsatisfiable_member_dependencies_conflicting() -> Result<()> {
----- stderr -----
Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
× No solution found when resolving dependencies:
╰─▶ Because only bar==0.1.0 is available and bar==0.1.0 depends on anyio==4.2.0, we can conclude that all versions of bar depend on anyio==4.2.0.
And because foo==0.1.0 depends on anyio==4.1.0 and only foo==0.1.0 is available, we can conclude that all versions of bar and all versions of foo are incompatible.
╰─▶ Because bar is a workspace member and bar==0.1.0 depends on anyio==4.2.0, we can conclude that all versions of bar depend on anyio==4.2.0.
And because foo==0.1.0 depends on anyio==4.1.0 and foo is a workspace member, we can conclude that all versions of bar and all versions of foo are incompatible.
And because you require bar and foo, we can conclude that the requirements are unsatisfiable.
"###
);
Expand Down Expand Up @@ -1324,8 +1324,8 @@ fn workspace_unsatisfiable_member_dependencies_conflicting_threeway() -> Result<
----- stderr -----
Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
× No solution found when resolving dependencies:
╰─▶ Because only bird==0.1.0 is available and bird==0.1.0 depends on anyio==4.3.0, we can conclude that all versions of bird depend on anyio==4.3.0.
And because knot==0.1.0 depends on anyio==4.2.0 and only knot==0.1.0 is available, we can conclude that all versions of bird and all versions of knot are incompatible.
╰─▶ Because bird is a workspace member and bird==0.1.0 depends on anyio==4.3.0, we can conclude that all versions of bird depend on anyio==4.3.0.
And because knot==0.1.0 depends on anyio==4.2.0 and knot is a workspace member, we can conclude that all versions of bird and all versions of knot are incompatible.
And because you require bird and knot, we can conclude that the requirements are unsatisfiable.
"###
);
Expand Down

0 comments on commit f0de4f7

Please sign in to comment.