Skip to content

Commit

Permalink
Merge external
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Apr 19, 2024
1 parent 97951bb commit 3db0ff4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 115 deletions.
24 changes: 15 additions & 9 deletions examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use pubgrub::error::PubGrubError;
use pubgrub::range::Range;
use pubgrub::report::Reporter;
use pubgrub::report::{DerivationTree, Reporter};
use pubgrub::solver::{resolve, OfflineDependencyProvider};
use pubgrub::version::SemanticVersion;

use pubgrub::report::{DefaultStringReporter, External, ReportFormatter};
use pubgrub::report::{DefaultStringReporter, ReportFormatter};
use pubgrub::term::Term;
use pubgrub::type_aliases::Map;
use std::fmt::{self, Display};
Expand Down Expand Up @@ -49,10 +49,10 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
format!("{package} {range} is mandatory")
}
[(p1, Term::Positive(r1)), (p2, Term::Negative(r2))] => {
External::FromDependencyOf(p1, r1.clone(), p2, r2.clone()).to_string()
DerivationTree::FromDependencyOf(p1, r1.clone(), p2, r2.clone()).to_string()
}
[(p1, Term::Negative(r1)), (p2, Term::Positive(r2))] => {
External::FromDependencyOf(p2, r2.clone(), p1, r1.clone()).to_string()
DerivationTree::FromDependencyOf(p2, r2.clone(), p1, r1.clone()).to_string()
}
slice => {
let str_terms: Vec<_> = slice.iter().map(|(p, t)| format!("{p} {t}")).collect();
Expand All @@ -61,26 +61,29 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
}
}

fn format_external(&self, external: &External<Package, Range<SemanticVersion>>) -> String {
fn format_external(
&self,
external: &DerivationTree<Package, Range<SemanticVersion>>,
) -> String {
match external {
External::NotRoot(package, version) => {
DerivationTree::NotRoot(package, version) => {
format!("we are solving dependencies of {package} {version}")
}
External::NoVersions(package, set) => {
DerivationTree::NoVersions(package, set) => {
if set == &Range::full() {
format!("there is no available version for {package}")
} else {
format!("there is no version of {package} in {set}")
}
}
External::UnavailableDependencies(package, set) => {
DerivationTree::UnavailableDependencies(package, set) => {
if set == &Range::full() {
format!("dependencies of {package} are unavailable")
} else {
format!("dependencies of {package} at version {set} are unavailable")
}
}
External::FromDependencyOf(package, package_set, dependency, dependency_set) => {
DerivationTree::FromDependencyOf(package, package_set, dependency, dependency_set) => {
if package_set == &Range::full() && dependency_set == &Range::full() {
format!("{package} depends on {dependency}")
} else if package_set == &Range::full() {
Expand All @@ -99,6 +102,9 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
format!("{package} {package_set} depends on {dependency} {dependency_set}")
}
}
DerivationTree::Derived(_) => {
panic!("Got derived, while only external can be formatted");
}
}
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use std::sync::Arc;
use crate::internal::arena::{Arena, Id};
use crate::internal::small_map::SmallMap;
use crate::package::Package;
use crate::report::{
DefaultStringReportFormatter, DerivationTree, Derived, External, ReportFormatter,
};
use crate::report::{DefaultStringReportFormatter, DerivationTree, Derived, ReportFormatter};
use crate::term::{self, Term};
use crate::type_aliases::{Map, Set};
use crate::version_set::VersionSet;
Expand Down Expand Up @@ -249,18 +247,14 @@ impl<P: Package, VS: VersionSet> Incompatibility<P, VS> {
};
DerivationTree::Derived(derived)
}
Kind::NotRoot(package, version) => {
DerivationTree::External(External::NotRoot(package, version))
}
Kind::NoVersions(package, set) => {
DerivationTree::External(External::NoVersions(package, set))
}
Kind::NotRoot(package, version) => DerivationTree::NotRoot(package, version),
Kind::NoVersions(package, set) => DerivationTree::NoVersions(package, set),
Kind::UnavailableDependencies(package, set) => {
DerivationTree::External(External::UnavailableDependencies(package, set))
DerivationTree::UnavailableDependencies(package, set)
}
Kind::FromDependencyOf(package, set, dep_package, dep_set) => {
DerivationTree::FromDependencyOf(package, set, dep_package, dep_set)
}
Kind::FromDependencyOf(package, set, dep_package, dep_set) => DerivationTree::External(
External::FromDependencyOf(package, set, dep_package, dep_set),
),
}
}
}
Expand Down
Loading

0 comments on commit 3db0ff4

Please sign in to comment.