Fix formatting of negated singleton versions in error messages (#836)

Closes #805 
Requires https://github.com/zanieb/pubgrub/pull/17
This commit is contained in:
Zanie Blue 2024-01-08 12:33:01 -06:00 committed by GitHub
parent c3d37db85b
commit 2b0c2e294b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 9 deletions

2
Cargo.lock generated
View File

@ -2246,7 +2246,7 @@ dependencies = [
[[package]] [[package]]
name = "pubgrub" name = "pubgrub"
version = "0.2.1" version = "0.2.1"
source = "git+https://github.com/zanieb/pubgrub?rev=78b8add6942766e5fb070bbda1de570e93d6399f#78b8add6942766e5fb070bbda1de570e93d6399f" source = "git+https://github.com/zanieb/pubgrub?rev=866c0f2a87fee1e8abe804d40a2ee934de0973d7#866c0f2a87fee1e8abe804d40a2ee934de0973d7"
dependencies = [ dependencies = [
"indexmap 2.1.0", "indexmap 2.1.0",
"log", "log",

View File

@ -52,7 +52,7 @@ owo-colors = { version = "3.5.0" }
petgraph = { version = "0.6.4" } petgraph = { version = "0.6.4" }
platform-info = { version = "2.0.2" } platform-info = { version = "2.0.2" }
plist = { version = "1.6.0" } plist = { version = "1.6.0" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "78b8add6942766e5fb070bbda1de570e93d6399f" } pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "866c0f2a87fee1e8abe804d40a2ee934de0973d7" }
pyo3 = { version = "0.20.2" } pyo3 = { version = "0.20.2" }
pyo3-log = { version = "0.9.0"} pyo3-log = { version = "0.9.0"}
pyproject-toml = { version = "0.8.1" } pyproject-toml = { version = "0.8.1" }

View File

@ -262,7 +262,7 @@ fn dependency_excludes_range_of_compatible_versions() -> Result<()> {
Because there is no version of c available matching <1.0.0 | >1.0.0, <2.0.0 | >2.0.0 and c==1.0.0 depends on a<2.0.0, c<2.0.0 depends on a<2.0.0. Because there is no version of c available matching <1.0.0 | >1.0.0, <2.0.0 | >2.0.0 and c==1.0.0 depends on a<2.0.0, c<2.0.0 depends on a<2.0.0.
And because c==2.0.0 depends on a>=3.0.0, c depends on a<2.0.0 | >=3.0.0. And because c==2.0.0 depends on a>=3.0.0, c depends on a<2.0.0 | >=3.0.0.
And because a<2.0.0 depends on b==1.0.0 (1), a Not ( ==3.0.0 ), c *, b Not ( ==1.0.0 ) are incompatible. And because a<2.0.0 depends on b==1.0.0 (1), a!=3.0.0, c*, b!=1.0.0 are incompatible.
And because a==3.0.0 depends on b==3.0.0, c depends on b<=1.0.0 | >=3.0.0. And because a==3.0.0 depends on b==3.0.0, c depends on b<=1.0.0 | >=3.0.0.
And because root depends on c and root depends on b>=2.0.0, <3.0.0, version solving failed. And because root depends on c and root depends on b>=2.0.0, <3.0.0, version solving failed.
"###); "###);
@ -1466,7 +1466,7 @@ fn requires_transitive_prerelease_and_stable_dependency_many_versions() -> Resul
× No solution found when resolving dependencies: × No solution found when resolving dependencies:
Because there is no version of b available matching <1.0.0 | >1.0.0 and b==1.0.0 depends on c, b depends on c. Because there is no version of b available matching <1.0.0 | >1.0.0 and b==1.0.0 depends on c, b depends on c.
And because there is no version of c available matching >=2.0.0b1, b depends on c<2.0.0b1. And because there is no version of c available matching >=2.0.0b1, b depends on c<2.0.0b1.
And because a==1.0.0 depends on c>=2.0.0b1 and there is no version of a available matching <1.0.0 | >1.0.0, b *, a * are incompatible. And because a==1.0.0 depends on c>=2.0.0b1 and there is no version of a available matching <1.0.0 | >1.0.0, b*, a* are incompatible.
And because root depends on b and root depends on a, version solving failed. And because root depends on b and root depends on a, version solving failed.
hint: c was requested with a pre-release marker (e.g., >=2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`) hint: c was requested with a pre-release marker (e.g., >=2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`)
@ -2051,7 +2051,7 @@ fn requires_transitive_incompatible_with_transitive() -> Result<()> {
----- stderr ----- ----- stderr -----
× No solution found when resolving dependencies: × No solution found when resolving dependencies:
Because there is no version of b available matching <1.0.0 | >1.0.0 and b==1.0.0 depends on c==2.0.0, b depends on c==2.0.0. Because there is no version of b available matching <1.0.0 | >1.0.0 and b==1.0.0 depends on c==2.0.0, b depends on c==2.0.0.
And because a==1.0.0 depends on c==1.0.0 and there is no version of a available matching <1.0.0 | >1.0.0, a *, b * are incompatible. And because a==1.0.0 depends on c==1.0.0 and there is no version of a available matching <1.0.0 | >1.0.0, a*, b* are incompatible.
And because root depends on b and root depends on a, version solving failed. And because root depends on b and root depends on a, version solving failed.
"###); "###);
}); });
@ -2447,11 +2447,11 @@ fn requires_python_version_greater_than_current_excluded() -> Result<()> {
----- stderr ----- ----- stderr -----
× No solution found when resolving dependencies: × No solution found when resolving dependencies:
Because there is no version of Python available matching >=3.10, <3.11 and there is no version of Python available matching >=3.12, Python >=3.10, <3.11 | >=3.12 are incompatible. Because there is no version of Python available matching >=3.10, <3.11 and there is no version of Python available matching >=3.12, Python>=3.10, <3.11 | >=3.12 are incompatible.
And because there is no version of Python available matching >=3.11, <3.12, Python >=3.10 are incompatible. And because there is no version of Python available matching >=3.11, <3.12, Python>=3.10 are incompatible.
And because a==2.0.0 depends on Python>=3.10 and there is no version of a available matching >2.0.0, <3.0.0 | >3.0.0, <4.0.0 | >4.0.0, a>=2.0.0, <3.0.0 is forbidden. (1) And because a==2.0.0 depends on Python>=3.10 and there is no version of a available matching >2.0.0, <3.0.0 | >3.0.0, <4.0.0 | >4.0.0, a>=2.0.0, <3.0.0 is forbidden. (1)
Because there is no version of Python available matching >=3.11, <3.12 and there is no version of Python available matching >=3.12, Python >=3.11 are incompatible. Because there is no version of Python available matching >=3.11, <3.12 and there is no version of Python available matching >=3.12, Python>=3.11 are incompatible.
And because a==3.0.0 depends on Python>=3.11, a==3.0.0 is forbidden. And because a==3.0.0 depends on Python>=3.11, a==3.0.0 is forbidden.
And because a>=2.0.0, <3.0.0 is forbidden (1), a>=2.0.0, <4.0.0 is forbidden. (2) And because a>=2.0.0, <3.0.0 is forbidden (1), a>=2.0.0, <4.0.0 is forbidden. (2)

View File

@ -125,7 +125,10 @@ impl ReportFormatter<PubGrubPackage, Range<PubGrubVersion>> for PubGrubReportFor
&External::FromDependencyOf((*p2).clone(), r2.clone(), (*p1).clone(), r1.clone()), &External::FromDependencyOf((*p2).clone(), r2.clone(), (*p1).clone(), r1.clone()),
), ),
slice => { slice => {
let str_terms: Vec<_> = slice.iter().map(|(p, t)| format!("{p} {t}")).collect(); let str_terms: Vec<_> = slice
.iter()
.map(|(p, t)| format!("{p}{}", PubGrubTerm::from_term((*t).clone())))
.collect();
str_terms.join(", ") + " are incompatible" str_terms.join(", ") + " are incompatible"
} }
} }
@ -232,3 +235,29 @@ impl std::fmt::Display for PubGrubHint {
} }
} }
} }
/// A derivative of the [Term] type with custom formatting.
struct PubGrubTerm {
inner: Term<Range<PubGrubVersion>>,
}
impl std::fmt::Display for PubGrubTerm {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.inner {
Term::Positive(set) => write!(f, "{set}"),
Term::Negative(set) => {
if let Some(version) = set.as_singleton() {
write!(f, "!={version}")
} else {
write!(f, "!( {set} )")
}
}
}
}
}
impl PubGrubTerm {
fn from_term(term: Term<Range<PubGrubVersion>>) -> PubGrubTerm {
PubGrubTerm { inner: term }
}
}