Skip to content

Commit 8afbd86

Browse files
authored
make ErrorTree for NoSolutionError externally accessible (#14444)
Hey, are you okay with exposing the `ErrorTree` for library consumers? We have a use case that needs more information on conflicts. We need the tree-structure of the conflict and be able to traverse it in particular. Signed-off-by: Simon Sure <[email protected]>
1 parent a1cda62 commit 8afbd86

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

crates/uv-resolver/src/error.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<T> From<tokio::sync::mpsc::error::SendError<T>> for ResolveError {
156156
}
157157
}
158158

159-
pub(crate) type ErrorTree = DerivationTree<PubGrubPackage, Range<Version>, UnavailableReason>;
159+
pub type ErrorTree = DerivationTree<PubGrubPackage, Range<Version>, UnavailableReason>;
160160

161161
/// A wrapper around [`pubgrub::error::NoSolutionError`] that displays a resolution failure report.
162162
pub struct NoSolutionError {
@@ -367,6 +367,11 @@ impl NoSolutionError {
367367
NoSolutionHeader::new(self.env.clone())
368368
}
369369

370+
/// Get the conflict derivation tree for external analysis
371+
pub fn derivation_tree(&self) -> &ErrorTree {
372+
&self.error
373+
}
374+
370375
/// Hint at limiting the resolver environment if universal resolution failed for a target
371376
/// that is not the current platform or not the current Python version.
372377
fn hint_disjoint_targets(&self, f: &mut Formatter) -> std::fmt::Result {

crates/uv-resolver/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use dependency_mode::DependencyMode;
2-
pub use error::{NoSolutionError, NoSolutionHeader, ResolveError, SentinelRange};
2+
pub use error::{ErrorTree, NoSolutionError, NoSolutionHeader, ResolveError, SentinelRange};
33
pub use exclude_newer::ExcludeNewer;
44
pub use exclusions::Exclusions;
55
pub use flat_index::{FlatDistributions, FlatIndex};
@@ -54,7 +54,7 @@ mod options;
5454
mod pins;
5555
mod preferences;
5656
mod prerelease;
57-
mod pubgrub;
57+
pub mod pubgrub;
5858
mod python_requirement;
5959
mod redirect;
6060
mod resolution;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub(crate) use crate::pubgrub::dependencies::PubGrubDependency;
22
pub(crate) use crate::pubgrub::distribution::PubGrubDistribution;
3-
pub(crate) use crate::pubgrub::package::{PubGrubPackage, PubGrubPackageInner, PubGrubPython};
3+
pub use crate::pubgrub::package::{PubGrubPackage, PubGrubPackageInner, PubGrubPython};
44
pub(crate) use crate::pubgrub::priority::{PubGrubPriorities, PubGrubPriority, PubGrubTiebreaker};
55
pub(crate) use crate::pubgrub::report::PubGrubReportFormatter;
66

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::python_requirement::PythonRequirement;
99

1010
/// [`Arc`] wrapper around [`PubGrubPackageInner`] to make cloning (inside PubGrub) cheap.
1111
#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
12-
pub(crate) struct PubGrubPackage(Arc<PubGrubPackageInner>);
12+
pub struct PubGrubPackage(Arc<PubGrubPackageInner>);
1313

1414
impl Deref for PubGrubPackage {
1515
type Target = PubGrubPackageInner;
@@ -39,7 +39,7 @@ impl From<PubGrubPackageInner> for PubGrubPackage {
3939
/// package (e.g., `black[colorama]`), and mark it as a dependency of the real package (e.g.,
4040
/// `black`). We then discard the virtual packages at the end of the resolution process.
4141
#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
42-
pub(crate) enum PubGrubPackageInner {
42+
pub enum PubGrubPackageInner {
4343
/// The root package, which is used to start the resolution process.
4444
Root(Option<PackageName>),
4545
/// A Python version.
@@ -295,7 +295,7 @@ impl PubGrubPackage {
295295
}
296296

297297
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Hash, Ord)]
298-
pub(crate) enum PubGrubPython {
298+
pub enum PubGrubPython {
299299
/// The Python version installed in the current environment.
300300
Installed,
301301
/// The Python version for which dependencies are being resolved.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use uv_platform_tags::{AbiTag, Tags};
77

88
/// The reason why a package or a version cannot be used.
99
#[derive(Debug, Clone, Eq, PartialEq)]
10-
pub(crate) enum UnavailableReason {
10+
pub enum UnavailableReason {
1111
/// The entire package cannot be used.
1212
Package(UnavailablePackage),
1313
/// A single version cannot be used.
@@ -29,7 +29,7 @@ impl Display for UnavailableReason {
2929
/// Most variant are from [`MetadataResponse`] without the error source, since we don't format
3030
/// the source and we want to merge unavailable messages across versions.
3131
#[derive(Debug, Clone, Eq, PartialEq)]
32-
pub(crate) enum UnavailableVersion {
32+
pub enum UnavailableVersion {
3333
/// Version is incompatible because it has no usable distributions
3434
IncompatibleDist(IncompatibleDist),
3535
/// The wheel metadata was found, but could not be parsed.
@@ -123,7 +123,7 @@ impl From<&MetadataUnavailable> for UnavailableVersion {
123123

124124
/// The package is unavailable and cannot be used.
125125
#[derive(Debug, Clone, Eq, PartialEq)]
126-
pub(crate) enum UnavailablePackage {
126+
pub enum UnavailablePackage {
127127
/// Index lookups were disabled (i.e., `--no-index`) and the package was not found in a flat index (i.e. from `--find-links`).
128128
NoIndex,
129129
/// Network requests were disabled (i.e., `--offline`), and the package was not found in the cache.

0 commit comments

Comments
 (0)