Skip to content

Commit

Permalink
uv-resolver: use new simplify/complexify marker routines
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BurntSushi committed Sep 6, 2024
1 parent 3731cb9 commit a58a1a6
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions crates/uv-resolver/src/requires_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,8 @@ impl RequiresPython {
/// markers are "complexified" to put the `requires-python` assumption back
/// into the marker explicitly.
pub(crate) fn simplify_markers(&self, marker: MarkerTree) -> MarkerTree {
let simplified = marker.simplify_python_versions(Range::from(self.range().clone()));
// FIXME: This is a hack to avoid the hidden state created by
// 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)
let (lower, upper) = (self.range().lower(), self.range().upper());
marker.simplify_python_versions(lower.0.as_ref(), upper.0.as_ref())
}

/// The inverse of `simplify_markers`.
Expand All @@ -342,13 +336,9 @@ impl RequiresPython {
/// ```text
/// python_full_version >= '3.8' and python_full_version < '3.12'
/// ```
pub(crate) fn complexify_markers(&self, mut marker: MarkerTree) -> MarkerTree {
// PERF: There's likely a way to amortize this, particularly
// the construction of `to_marker_tree`. But at time of
// 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
pub(crate) fn complexify_markers(&self, marker: MarkerTree) -> MarkerTree {
let (lower, upper) = (self.range().lower(), self.range().upper());
marker.complexify_python_versions(lower.0.as_ref(), upper.0.as_ref())
}

/// Returns `false` if the wheel's tags state it can't be used in the given Python version
Expand Down

0 comments on commit a58a1a6

Please sign in to comment.