Skip to content
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
13 changes: 13 additions & 0 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ impl Lock {
python_full_version.clone(),
);
}

for markers in &mut package.fork_markers {
*markers = markers.clone().simplify_python_versions(
python_version.clone(),
python_full_version.clone(),
);
}
}

for markers in &mut lock.fork_markers {
*markers = markers
.clone()
.simplify_python_versions(python_version.clone(), python_full_version.clone());
}
}

Expand Down
12 changes: 0 additions & 12 deletions crates/uv-resolver/src/python_requirement.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pep440_rs::{Version, VersionSpecifiers};
use pep508_rs::MarkerTree;
use uv_python::{Interpreter, PythonVersion};

use crate::{RequiresPython, RequiresPythonBound};
Expand Down Expand Up @@ -70,17 +69,6 @@ impl PythonRequirement {
pub fn target(&self) -> Option<&PythonTarget> {
self.target.as_ref()
}

/// Return a [`MarkerTree`] representing the Python requirement.
///
/// See: [`RequiresPython::to_marker_tree`]
pub fn to_marker_tree(&self) -> Option<MarkerTree> {
if let Some(PythonTarget::RequiresPython(requires_python)) = self.target.as_ref() {
Some(requires_python.to_marker_tree())
} else {
None
}
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
62 changes: 1 addition & 61 deletions crates/uv-resolver/src/requires_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use itertools::Itertools;
use pubgrub::Range;

use distribution_filename::WheelFilename;
use pep440_rs::{Operator, Version, VersionSpecifier, VersionSpecifiers};
use pep508_rs::{MarkerExpression, MarkerTree, MarkerValueVersion};
use pep440_rs::{Version, VersionSpecifier, VersionSpecifiers};

#[derive(thiserror::Error, Debug)]
pub enum RequiresPythonError {
Expand Down Expand Up @@ -196,65 +195,6 @@ impl RequiresPython {
}
}

/// Returns this `Requires-Python` specifier as an equivalent marker
/// expression utilizing the `python_version` marker field.
///
/// This is useful for comparing a `Requires-Python` specifier with
/// arbitrary marker expressions. For example, one can ask whether the
/// returned marker expression is disjoint with another marker expression.
/// If it is, then one can conclude that the `Requires-Python` specifier
/// excludes the dependency with that other marker expression.
///
/// If this `Requires-Python` specifier has no constraints, then this
/// returns a marker tree that evaluates to `true` for all possible marker
/// environments.
pub fn to_marker_tree(&self) -> MarkerTree {
let (op, version) = match self.bound.as_ref() {
// If we see this anywhere, then it implies the marker
// tree we would generate would always evaluate to
// `true` because every possible Python version would
// satisfy it.
Bound::Unbounded => return MarkerTree::TRUE,
Bound::Excluded(version) => (Operator::GreaterThan, version.clone().without_local()),
Bound::Included(version) => {
(Operator::GreaterThanEqual, version.clone().without_local())
}
};
// For the `python_version` marker expression, it specifically only
// supports truncate major/minor versions of Python. This means that
// a `Requires-Python: 3.10.1` is satisfied by `python_version ==
// '3.10'`. So for disjointness checking, we need to ensure that the
// marker expression we generate for `Requires-Python` doesn't try to
// be overly selective about the patch version. We do this by keeping
// this part of our marker limited to the major and minor version
// components only.
let version_major_minor_only = Version::new(version.release().iter().take(2));
let expr_python_version = MarkerExpression::Version {
key: MarkerValueVersion::PythonVersion,
// OK because a version specifier is only invalid when the
// version is local (which is impossible here because we
// strip it above) or if the operator is ~= (which is also
// impossible here).
specifier: VersionSpecifier::from_version(op, version_major_minor_only).unwrap(),
};
let expr_python_full_version = MarkerExpression::Version {
key: MarkerValueVersion::PythonFullVersion,
// For `python_full_version`, we can use the entire
// version as-is.
//
// OK because a version specifier is only invalid when the
// version is local (which is impossible here because we
// strip it above) or if the operator is ~= (which is also
// impossible here).
specifier: VersionSpecifier::from_version(op, version).unwrap(),
};

let mut conjunction = MarkerTree::TRUE;
conjunction.and(MarkerTree::expression(expr_python_version));
conjunction.and(MarkerTree::expression(expr_python_full_version));
conjunction
}

/// Returns `false` if the wheel's tags state it can't be used in the given Python version
/// range.
///
Expand Down
16 changes: 0 additions & 16 deletions crates/uv-resolver/src/resolution/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use petgraph::{
graph::{Graph, NodeIndex},
Directed, Direction,
};
use pubgrub::Range;
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};

use distribution_types::{
Expand Down Expand Up @@ -169,21 +168,6 @@ impl ResolutionGraph {
.and_then(PythonTarget::as_requires_python)
.cloned();

// Normalize any markers.
if let Some(ref requires_python) = requires_python {
for edge in petgraph.edge_indices() {
petgraph[edge] = petgraph[edge].clone().simplify_python_versions(
Range::from(requires_python.bound_major_minor().clone()),
Range::from(requires_python.bound().clone()),
);
}
// The above simplification may turn some markers into
// "always false." In which case, we should remove that
// edge since it can never be traversed in any marker
// environment.
petgraph.retain_edges(|graph, edge| !graph[edge].is_false());
}

let fork_markers = if let [resolution] = resolutions {
match resolution.markers {
ResolverMarkers::Universal { .. } | ResolverMarkers::SpecificEnvironment(_) => {
Expand Down
Loading