Skip to content

Commit

Permalink
Use a custom pubgrub report formatter (#521)
Browse files Browse the repository at this point in the history
Uses astral-sh/pubgrub#10 to drastically simplify
our reporter implementation. This will allow us to make use of upstream
improvements to the reporter e.g.
astral-sh/pubgrub#8 without multiple duplicative
pull requests.
  • Loading branch information
zanieb authored Dec 1, 2023
1 parent efcc4f1 commit 2a8544d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 405 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ once_cell = { version = "1.18.0" }
petgraph = { version = "0.6.4" }
platform-info = { version = "2.0.2" }
plist = { version = "1.6.0" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "725b9a8e323c9ae0727fed2d045bad64eb212167" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "c4ffd26715df9f21067983b0eb176dfd14876133" }
pyo3 = { version = "0.20.0" }
pyo3-log = { version = "0.9.0"}
pyproject-toml = { version = "0.8.0" }
Expand Down
7 changes: 4 additions & 3 deletions crates/puffin-resolver/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Formatter;

use pubgrub::range::Range;
use pubgrub::report::Reporter;
use pubgrub::report::{DefaultStringReporter, Reporter};
use thiserror::Error;
use url::Url;

Expand All @@ -11,7 +11,7 @@ use puffin_distribution::DistributionDatabaseError;
use puffin_normalize::PackageName;

use crate::pubgrub::{PubGrubPackage, PubGrubVersion};
use crate::ResolutionFailureReporter;
use crate::PubGrubReportFormatter;

#[derive(Error, Debug)]
pub enum ResolveError {
Expand Down Expand Up @@ -78,7 +78,8 @@ impl std::error::Error for RichPubGrubError {}
impl std::fmt::Display for RichPubGrubError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if let pubgrub::error::PubGrubError::NoSolution(derivation_tree) = &self.source {
let report = ResolutionFailureReporter::report(derivation_tree);
let formatter = PubGrubReportFormatter;
let report = DefaultStringReporter::report_with_formatter(derivation_tree, &formatter);
write!(f, "{report}")
} else {
write!(f, "{}", self.source)
Expand Down
2 changes: 1 addition & 1 deletion crates/puffin-resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use error::ResolveError;
pub use finder::{DistFinder, Reporter as FinderReporter};
pub use manifest::Manifest;
pub use prerelease_mode::PreReleaseMode;
pub use pubgrub::ResolutionFailureReporter;
pub use pubgrub::PubGrubReportFormatter;
pub use resolution::Graph;
pub use resolution_mode::ResolutionMode;
pub use resolution_options::ResolutionOptions;
Expand Down
2 changes: 1 addition & 1 deletion crates/puffin-resolver/src/pubgrub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(crate) use crate::pubgrub::package::PubGrubPackage;
pub(crate) use crate::pubgrub::priority::{PubGrubPriorities, PubGrubPriority};
pub use crate::pubgrub::report::ResolutionFailureReporter;
pub use crate::pubgrub::report::PubGrubReportFormatter;

pub(crate) use crate::pubgrub::version::{PubGrubVersion, MIN_VERSION};

Expand Down
Loading

0 comments on commit 2a8544d

Please sign in to comment.