uv-resolver: use Requires-Python to filter dependencies during universal resolution

In the time before universal resolving, we would always pass a
`MarkerEnvironment`, and this environment would capture any relevant
`Requires-Python` specifier (including if `-p/--python` was provided on
the CLI).

But in universal resolution, we very specifically do not use a
`MarkerEnvironment` because we want to produce a resolution that is
compatible across potentially multiple environments. This in turn meant
that we lost `Requires-Python` filtering.

This PR adds it back. We do this by converting our `PythonRequirement`
into a `MarkerTree` that encodes the version specifiers in a
`Requires-Python` specifier. We then ask whether that `MarkerTree` is
disjoint with a dependency specification's `MarkerTree`. If it is, then
we know it's impossible for that dependency specification to every be
true, and we can completely ignore it.
This commit is contained in:
Andrew Gallant 2024-06-11 09:57:10 -04:00 committed by Andrew Gallant
parent c32667caec
commit 75b323232d
8 changed files with 147 additions and 422 deletions

View file

@ -58,6 +58,12 @@ impl PythonRequirement {
pub fn target(&self) -> Option<&PythonTarget> {
self.target.as_ref()
}
/// Return the target version of Python as a "requires python" type,
/// if available.
pub(crate) fn requires_python(&self) -> Option<&RequiresPython> {
self.target().and_then(|target| target.as_requires_python())
}
}
#[derive(Debug, Clone, Eq, PartialEq)]