diff --git a/crates/puffin-resolver/src/error.rs b/crates/puffin-resolver/src/error.rs index 5ab021a97..09d8d3a97 100644 --- a/crates/puffin-resolver/src/error.rs +++ b/crates/puffin-resolver/src/error.rs @@ -130,14 +130,7 @@ pub struct NoSolutionError { derivation_tree: DerivationTree>, available_versions: FxHashMap>, selector: Option, - python_requirement: Option, -} - -/// Derivative of [`PythonRequirement`] with owned data for error reporting. -#[derive(Debug, Clone)] -pub(crate) struct SolutionPythonRequirement { - pub(crate) installed: Version, - pub(crate) target: Version, + python_requirement: Option, } impl std::error::Error for NoSolutionError {} @@ -219,10 +212,7 @@ impl NoSolutionError { mut self, python_requirement: &PythonRequirement, ) -> Self { - self.python_requirement = Some(SolutionPythonRequirement { - target: python_requirement.target().clone(), - installed: python_requirement.installed().clone(), - }); + self.python_requirement = Some(python_requirement.clone()); self } } diff --git a/crates/puffin-resolver/src/pubgrub/report.rs b/crates/puffin-resolver/src/pubgrub/report.rs index feb4a2270..8143030ee 100644 --- a/crates/puffin-resolver/src/pubgrub/report.rs +++ b/crates/puffin-resolver/src/pubgrub/report.rs @@ -12,8 +12,8 @@ use pubgrub::type_aliases::Map; use rustc_hash::{FxHashMap, FxHashSet}; use crate::candidate_selector::CandidateSelector; -use crate::error::SolutionPythonRequirement; use crate::prerelease_mode::PreReleaseStrategy; +use crate::python_requirement::PythonRequirement; use super::PubGrubPackage; @@ -23,7 +23,7 @@ pub(crate) struct PubGrubReportFormatter<'a> { pub(crate) available_versions: &'a FxHashMap>, /// The versions that were available for each package - pub(crate) python_requirement: Option<&'a SolutionPythonRequirement>, + pub(crate) python_requirement: Option<&'a PythonRequirement>, } impl ReportFormatter> for PubGrubReportFormatter<'_> { @@ -37,8 +37,8 @@ impl ReportFormatter> for PubGrubReportFormatter< External::NoVersions(package, set) => { if matches!(package, PubGrubPackage::Python(_)) { if let Some(python) = self.python_requirement { - if python.target.release().iter().eq(python - .installed + if python.target().release().iter().eq(python + .installed() .release() .iter() .take(2)) @@ -50,28 +50,28 @@ impl ReportFormatter> for PubGrubReportFormatter< // display instead. return format!( "the current {package} version ({}) does not satisfy {}", - python.target, + python.target(), PackageRange::compatibility(package, set) ); } // Complex case, the target was provided and differs from the installed one // Determine which Python version requirement was not met - if !set.contains(&python.target) { + if !set.contains(python.target()) { return format!( "the requested {package} version ({}) does not satisfy {}", - python.target, + python.target(), PackageRange::compatibility(package, set) ); } // TODO(zanieb): Explain to the user why the installed version is relevant // when they provided a target version; probably via a "hint" debug_assert!( - !set.contains(&python.installed), + !set.contains(python.installed()), "There should not be an incompatibility where the range is satisfied by both Python requirements" ); return format!( "the current {package} version ({}) does not satisfy {}", - python.installed, + python.installed(), PackageRange::compatibility(package, set) ); } diff --git a/crates/puffin-resolver/src/python_requirement.rs b/crates/puffin-resolver/src/python_requirement.rs index c1a26d50c..6d8f7dadb 100644 --- a/crates/puffin-resolver/src/python_requirement.rs +++ b/crates/puffin-resolver/src/python_requirement.rs @@ -3,30 +3,30 @@ use pep508_rs::MarkerEnvironment; use puffin_interpreter::Interpreter; #[derive(Debug, Clone)] -pub struct PythonRequirement<'a> { +pub struct PythonRequirement { /// The installed version of Python. - installed: &'a Version, + installed: Version, /// The target version of Python; that is, the version of Python for which we are resolving /// dependencies. This is typically the same as the installed version, but may be different /// when specifying an alternate Python version for the resolution. - target: &'a Version, + target: Version, } -impl<'a> PythonRequirement<'a> { - pub fn new(interpreter: &'a Interpreter, markers: &'a MarkerEnvironment) -> Self { +impl PythonRequirement { + pub fn new(interpreter: &Interpreter, markers: &MarkerEnvironment) -> Self { Self { - installed: interpreter.version(), - target: &markers.python_version.version, + installed: interpreter.version().clone(), + target: markers.python_version.version.clone(), } } /// Return the installed version of Python. - pub(crate) fn installed(&self) -> &'a Version { - self.installed + pub(crate) fn installed(&self) -> &Version { + &self.installed } /// Return the target version of Python. - pub(crate) fn target(&self) -> &'a Version { - self.target + pub(crate) fn target(&self) -> &Version { + &self.target } } diff --git a/crates/puffin-resolver/src/resolver/mod.rs b/crates/puffin-resolver/src/resolver/mod.rs index 4d9b8ec3f..964e12599 100644 --- a/crates/puffin-resolver/src/resolver/mod.rs +++ b/crates/puffin-resolver/src/resolver/mod.rs @@ -63,7 +63,7 @@ pub struct Resolver<'a, Provider: ResolverProvider> { overrides: Overrides, allowed_urls: AllowedUrls, markers: &'a MarkerEnvironment, - python_requirement: PythonRequirement<'a>, + python_requirement: PythonRequirement, selector: CandidateSelector, index: &'a InMemoryIndex, /// A map from [`PackageId`] to the `Requires-Python` version specifiers for that package. @@ -120,7 +120,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> { manifest: Manifest, options: ResolutionOptions, markers: &'a MarkerEnvironment, - python_requirement: PythonRequirement<'a>, + python_requirement: PythonRequirement, index: &'a InMemoryIndex, provider: Provider, ) -> Self { diff --git a/crates/puffin-resolver/src/resolver/provider.rs b/crates/puffin-resolver/src/resolver/provider.rs index 3f9ac5aa9..6f7bdb3e0 100644 --- a/crates/puffin-resolver/src/resolver/provider.rs +++ b/crates/puffin-resolver/src/resolver/provider.rs @@ -52,7 +52,7 @@ pub struct DefaultResolverProvider<'a, Context: BuildContext + Send + Sync> { /// These are the entries from `--find-links` that act as overrides for index responses. flat_index: &'a FlatIndex, tags: &'a Tags, - python_requirement: PythonRequirement<'a>, + python_requirement: PythonRequirement, exclude_newer: Option>, allowed_yanks: AllowedYanks, no_binary: &'a NoBinary, @@ -66,7 +66,7 @@ impl<'a, Context: BuildContext + Send + Sync> DefaultResolverProvider<'a, Contex fetcher: DistributionDatabase<'a, Context>, flat_index: &'a FlatIndex, tags: &'a Tags, - python_requirement: PythonRequirement<'a>, + python_requirement: PythonRequirement, exclude_newer: Option>, allowed_yanks: AllowedYanks, no_binary: &'a NoBinary,