diff --git a/crates/uv-resolver/src/resolver/mod.rs b/crates/uv-resolver/src/resolver/mod.rs index efb15a9ed..efa73c09e 100644 --- a/crates/uv-resolver/src/resolver/mod.rs +++ b/crates/uv-resolver/src/resolver/mod.rs @@ -451,56 +451,7 @@ impl ResolverState version, ResolverVersion::Unavailable(version, reason) => { - // Incompatible requires-python versions are special in that we track - // them as incompatible dependencies instead of marking the package version - // as unavailable directly - if let UnavailableVersion::IncompatibleDist( - IncompatibleDist::Source(IncompatibleSource::RequiresPython( - requires_python, - kind, - )) - | IncompatibleDist::Wheel(IncompatibleWheel::RequiresPython( - requires_python, - kind, - )), - ) = reason - { - let python_version: Range = - PubGrubSpecifier::try_from(&requires_python)?.into(); - - let package = &state.next; - state - .pubgrub - .add_incompatibility(Incompatibility::from_dependency( - package.clone(), - Range::singleton(version.clone()), - ( - PubGrubPackage::from(PubGrubPackageInner::Python( - match kind { - PythonRequirementKind::Installed => { - PubGrubPython::Installed - } - PythonRequirementKind::Target => { - PubGrubPython::Target - } - }, - )), - python_version.clone(), - ), - )); - state - .pubgrub - .partial_solution - .add_decision(state.next.clone(), version); - continue; - }; - state - .pubgrub - .add_incompatibility(Incompatibility::custom_version( - state.next.clone(), - version.clone(), - UnavailableReason::Version(reason), - )); + state.add_unavailable_version(version, reason)?; continue; } }; @@ -1800,6 +1751,49 @@ impl SolveState { Ok(()) } + fn add_unavailable_version( + &mut self, + version: Version, + reason: UnavailableVersion, + ) -> Result<(), ResolveError> { + // Incompatible requires-python versions are special in that we track + // them as incompatible dependencies instead of marking the package version + // as unavailable directly + if let UnavailableVersion::IncompatibleDist( + IncompatibleDist::Source(IncompatibleSource::RequiresPython(requires_python, kind)) + | IncompatibleDist::Wheel(IncompatibleWheel::RequiresPython(requires_python, kind)), + ) = reason + { + let python_version: Range = + PubGrubSpecifier::try_from(&requires_python)?.into(); + + let package = &self.next; + self.pubgrub + .add_incompatibility(Incompatibility::from_dependency( + package.clone(), + Range::singleton(version.clone()), + ( + PubGrubPackage::from(PubGrubPackageInner::Python(match kind { + PythonRequirementKind::Installed => PubGrubPython::Installed, + PythonRequirementKind::Target => PubGrubPython::Target, + })), + python_version.clone(), + ), + )); + self.pubgrub + .partial_solution + .add_decision(self.next.clone(), version); + return Ok(()); + }; + self.pubgrub + .add_incompatibility(Incompatibility::custom_version( + self.next.clone(), + version.clone(), + UnavailableReason::Version(reason), + )); + Ok(()) + } + fn into_resolution(self) -> Resolution { let solution = self.pubgrub.partial_solution.extract_solution(); let mut dependencies: FxHashMap<