uv-resolver: use new simplify/complexify marker routines

This finally gets rid of our hack for working around "hidden"
state. We no longer do a roundtrip marker serialization and
deserialization just to avoid the hidden state.
This commit is contained in:
Andrew Gallant 2024-09-06 14:09:01 -04:00 committed by Andrew Gallant
parent 2c139d6fca
commit f6bc701ac3
1 changed files with 5 additions and 15 deletions

View File

@ -317,14 +317,8 @@ impl RequiresPython {
/// markers are "complexified" to put the `requires-python` assumption back /// markers are "complexified" to put the `requires-python` assumption back
/// into the marker explicitly. /// into the marker explicitly.
pub(crate) fn simplify_markers(&self, marker: MarkerTree) -> MarkerTree { pub(crate) fn simplify_markers(&self, marker: MarkerTree) -> MarkerTree {
let simplified = marker.simplify_python_versions(Range::from(self.range().clone())); let (lower, upper) = (self.range().lower(), self.range().upper());
// FIXME: This is a hack to avoid the hidden state created by marker.simplify_python_versions(lower.0.as_ref(), upper.0.as_ref())
// ADD's `restrict_versions`. I believe this is sound, but it's
// wasteful and silly.
simplified
.try_to_string()
.map(|s| s.parse().unwrap())
.unwrap_or(MarkerTree::TRUE)
} }
/// The inverse of `simplify_markers`. /// The inverse of `simplify_markers`.
@ -342,13 +336,9 @@ impl RequiresPython {
/// ```text /// ```text
/// python_full_version >= '3.8' and python_full_version < '3.12' /// python_full_version >= '3.8' and python_full_version < '3.12'
/// ``` /// ```
pub(crate) fn complexify_markers(&self, mut marker: MarkerTree) -> MarkerTree { pub(crate) fn complexify_markers(&self, marker: MarkerTree) -> MarkerTree {
// PERF: There's likely a way to amortize this, particularly let (lower, upper) = (self.range().lower(), self.range().upper());
// the construction of `to_marker_tree`. But at time of marker.complexify_python_versions(lower.0.as_ref(), upper.0.as_ref())
// writing, it wasn't clear if this was an actual perf problem
// or not. If it is, try a `std::sync::OnceLock`.
marker.and(self.to_marker_tree());
marker
} }
/// Returns `false` if the wheel's tags state it can't be used in the given Python version /// Returns `false` if the wheel's tags state it can't be used in the given Python version