Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor requires-python marker simplification #6268

Merged
merged 15 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,7 @@ fn parse_file_path(input: &str) -> Result<PathBuf, String> {
url.to_file_path()
.map_err(|()| "invalid file URL".to_string())
} else {
match PathBuf::from_str(input) {
Ok(path) => Ok(path),
Err(err) => Err(err.to_string()),
}
Ok(PathBuf::from(input))
}
}

Expand Down
47 changes: 47 additions & 0 deletions crates/uv-resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl std::fmt::Display for NoSolutionError {

// Transform the error tree for reporting
let mut tree = self.error.clone();
simplify_derivation_tree_markers(&self.python_requirement, &mut tree);
let should_display_tree = std::env::var_os("UV_INTERNAL__SHOW_DERIVATION_TREE").is_some()
|| tracing::enabled!(tracing::Level::TRACE);

Expand Down Expand Up @@ -470,6 +471,52 @@ fn collapse_redundant_depends_on_no_versions_inner(
}
}

/// Simplifies the markers on pubgrub packages in the given derivation tree
/// according to the given Python requirement.
///
/// For example, when there's a dependency like `foo ; python_version >=
/// '3.11'` and `requires-python = '>=3.11'`, this simplification will remove
/// the `python_version >= '3.11'` marker since it's implied to be true by
/// the `requires-python` setting. This simplifies error messages by reducing
/// noise.
fn simplify_derivation_tree_markers(
python_requirement: &PythonRequirement,
tree: &mut DerivationTree<PubGrubPackage, Range<Version>, UnavailableReason>,
) {
match tree {
DerivationTree::External(External::NotRoot(ref mut pkg, _)) => {
pkg.simplify_markers(python_requirement);
}
DerivationTree::External(External::NoVersions(ref mut pkg, _)) => {
pkg.simplify_markers(python_requirement);
}
DerivationTree::External(External::FromDependencyOf(ref mut pkg1, _, ref mut pkg2, _)) => {
pkg1.simplify_markers(python_requirement);
pkg2.simplify_markers(python_requirement);
}
DerivationTree::External(External::Custom(ref mut pkg, _, _)) => {
pkg.simplify_markers(python_requirement);
}
DerivationTree::Derived(derived) => {
derived.terms = std::mem::take(&mut derived.terms)
.into_iter()
.map(|(mut pkg, term)| {
pkg.simplify_markers(python_requirement);
(pkg, term)
})
.collect();
simplify_derivation_tree_markers(
python_requirement,
Arc::make_mut(&mut derived.cause1),
);
simplify_derivation_tree_markers(
python_requirement,
Arc::make_mut(&mut derived.cause2),
);
}
}
}

/// Given a [`DerivationTree`], collapse incompatibilities for versions of a package that are
/// unavailable for the same reason to avoid repeating the same message for every unavailable
/// version.
Expand Down
Loading
Loading