Filter out markers based on Python requirement (#4912)

## Summary

In marker normalization, we now remove any markers that are redundant
with the `requires-python` specifier (i.e., always true for the given
Python requirement).

For example, given `iniconfig ; python_version >= '3.7'`, we can remove
the `python_version >= '3.7'` marker when resolving with
`--python-version 3.8`.

Closes #4852.
This commit is contained in:
Charlie Marsh 2024-07-09 09:15:58 -07:00 committed by GitHub
parent ef120dcc54
commit 72dd34b225
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 146 additions and 48 deletions

View file

@ -155,6 +155,11 @@ impl RequiresPython {
self.bound.as_ref() == Bound::Unbounded
}
/// Returns the [`RequiresPythonBound`] for the `Requires-Python` specifier.
pub fn bound(&self) -> &RequiresPythonBound {
&self.bound
}
/// Returns this `Requires-Python` specifier as an equivalent marker
/// expression utilizing the `python_version` marker field.
///
@ -254,6 +259,16 @@ impl RequiresPythonBound {
}
}
impl From<RequiresPythonBound> for Range<Version> {
fn from(value: RequiresPythonBound) -> Self {
match value.0 {
Bound::Included(version) => Range::higher_than(version),
Bound::Excluded(version) => Range::strictly_higher_than(version),
Bound::Unbounded => Range::full(),
}
}
}
impl Deref for RequiresPythonBound {
type Target = Bound<Version>;