From f060641ea0f85adad119150d1b92a76d50599e45 Mon Sep 17 00:00:00 2001 From: Zanie Date: Tue, 12 Dec 2023 13:26:53 -0600 Subject: [PATCH] Refactor as requested in review Fix PubGrub commit --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/puffin-resolver/src/pubgrub/report.rs | 71 +++++++------------- 3 files changed, 25 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d61648ddc14b0..7b71f1c0811cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2238,7 +2238,7 @@ dependencies = [ [[package]] name = "pubgrub" version = "0.2.1" -source = "git+https://github.com/zanieb/pubgrub?rev=c30acff93d541ea381128a502c61e2894388f57a#c30acff93d541ea381128a502c61e2894388f57a" +source = "git+https://github.com/zanieb/pubgrub?rev=8fff95d6a233a9fa4ee5ab5429033f0f0d3ddb20#8fff95d6a233a9fa4ee5ab5429033f0f0d3ddb20" dependencies = [ "indexmap 2.1.0", "log", diff --git a/Cargo.toml b/Cargo.toml index 3f6d81e6e979b..41f719558e1b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,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 = "c30acff93d541ea381128a502c61e2894388f57a" } +pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "8fff95d6a233a9fa4ee5ab5429033f0f0d3ddb20" } pyo3 = { version = "0.20.0" } pyo3-log = { version = "0.9.0"} pyproject-toml = { version = "0.8.0" } diff --git a/crates/puffin-resolver/src/pubgrub/report.rs b/crates/puffin-resolver/src/pubgrub/report.rs index cb55b4dfd5986..814005134dda5 100644 --- a/crates/puffin-resolver/src/pubgrub/report.rs +++ b/crates/puffin-resolver/src/pubgrub/report.rs @@ -12,6 +12,21 @@ pub struct PubGrubReportFormatter<'a> { pub available_versions: &'a FxHashMap>, } +impl PubGrubReportFormatter<'_> { + fn simplify_set( + &self, + set: &Range, + package: &PubGrubPackage, + ) -> Range { + set.simplify( + self.available_versions + .get(package) + .unwrap_or(&vec![]) + .iter(), + ) + } +} + impl ReportFormatter> for PubGrubReportFormatter<'_> { type Output = String; @@ -27,12 +42,7 @@ impl ReportFormatter> for PubGrubReportFor if set == &Range::full() { format!("there is no available version for {package}") } else { - let set = set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let set = self.simplify_set(set, package); format!("there is no version of {package} available matching {set}") } } @@ -40,12 +50,7 @@ impl ReportFormatter> for PubGrubReportFor if set == &Range::full() { format!("dependencies of {package} are unavailable") } else { - let set = set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let set = self.simplify_set(set, package); format!("dependencies of {package} at version {set} are unavailable") } } @@ -57,12 +62,7 @@ impl ReportFormatter> for PubGrubReportFor if set == &Range::full() { format!("dependencies of {package} are unusable: {reason}") } else { - let set = set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let set = self.simplify_set(set, package); format!("dependencies of {package}{set} are unusable: {reason}",) } } @@ -70,12 +70,7 @@ impl ReportFormatter> for PubGrubReportFor if set == &Range::full() { format!("dependencies of {package} are unusable") } else { - let set = set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let set = self.simplify_set(set, package); format!("dependencies of {package}{set} are unusable") } } @@ -84,43 +79,23 @@ impl ReportFormatter> for PubGrubReportFor if package_set == &Range::full() && dependency_set == &Range::full() { format!("{package} depends on {dependency}") } else if package_set == &Range::full() { - let dependency_set = dependency_set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let dependency_set = self.simplify_set(dependency_set, package); format!("{package} depends on {dependency}{dependency_set}") } else if dependency_set == &Range::full() { if matches!(package, PubGrubPackage::Root(_)) { // Exclude the dummy version for root packages format!("{package} depends on {dependency}") } else { - let package_set = package_set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let package_set = self.simplify_set(package_set, package); format!("{package}{package_set} depends on {dependency}") } } else { - let dependency_set = dependency_set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let dependency_set = self.simplify_set(dependency_set, package); if matches!(package, PubGrubPackage::Root(_)) { // Exclude the dummy version for root packages format!("{package} depends on {dependency}{dependency_set}") } else { - let package_set = package_set.simplify( - self.available_versions - .get(package) - .unwrap_or(&vec![]) - .iter(), - ); + let package_set = self.simplify_set(package_set, package); format!("{package}{package_set} depends on {dependency}{dependency_set}") } }