mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 10:50:29 +00:00
Use current and requested Python versions in requires-python incompatibility errors (#986)
Closes https://github.com/astral-sh/puffin/issues/806
This commit is contained in:
parent
23f73592b1
commit
6202c9e1b5
7 changed files with 96 additions and 25 deletions
|
|
@ -108,8 +108,10 @@ impl From<pubgrub::error::PubGrubError<PubGrubPackage, Range<Version>, Infallibl
|
|||
pubgrub::error::PubGrubError::NoSolution(derivation_tree) => {
|
||||
ResolveError::NoSolution(NoSolutionError {
|
||||
derivation_tree,
|
||||
// The following should be populated before display for the best error messages
|
||||
available_versions: FxHashMap::default(),
|
||||
selector: None,
|
||||
python_requirement: None,
|
||||
})
|
||||
}
|
||||
pubgrub::error::PubGrubError::SelfDependency { package, version } => {
|
||||
|
|
@ -128,6 +130,7 @@ pub struct NoSolutionError {
|
|||
derivation_tree: DerivationTree<PubGrubPackage, Range<Version>>,
|
||||
available_versions: FxHashMap<PubGrubPackage, Vec<Version>>,
|
||||
selector: Option<CandidateSelector>,
|
||||
python_requirement: Option<PythonRequirement>,
|
||||
}
|
||||
|
||||
impl std::error::Error for NoSolutionError {}
|
||||
|
|
@ -137,6 +140,7 @@ impl std::fmt::Display for NoSolutionError {
|
|||
// Write the derivation report.
|
||||
let formatter = PubGrubReportFormatter {
|
||||
available_versions: &self.available_versions,
|
||||
python_requirement: self.python_requirement.as_ref(),
|
||||
};
|
||||
let report =
|
||||
DefaultStringReporter::report_with_formatter(&self.derivation_tree, &formatter);
|
||||
|
|
@ -201,4 +205,14 @@ impl NoSolutionError {
|
|||
self.selector = Some(selector);
|
||||
self
|
||||
}
|
||||
|
||||
/// Update the Python requirements attached to the error.
|
||||
#[must_use]
|
||||
pub(crate) fn with_python_requirement(
|
||||
mut self,
|
||||
python_requirement: &PythonRequirement,
|
||||
) -> Self {
|
||||
self.python_requirement = Some(python_requirement.clone());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue