Skip to content

Commit 2a90f06

Browse files
committed
Remove python_version from lowered marker representation
1 parent df844e1 commit 2a90f06

File tree

6 files changed

+39
-105
lines changed

6 files changed

+39
-105
lines changed

crates/uv-pep508/src/lib.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
#![warn(missing_docs)]
1818

19-
use std::collections::HashSet;
2019
use std::error::Error;
2120
use std::fmt::{Debug, Display, Formatter};
2221
use std::path::Path;
@@ -41,7 +40,7 @@ pub use uv_normalize::{ExtraName, InvalidNameError, PackageName};
4140
/// Version and version specifiers used in requirements (reexport).
4241
// https://github.com/konstin/pep508_rs/issues/19
4342
pub use uv_pep440;
44-
use uv_pep440::{Version, VersionSpecifier, VersionSpecifiers};
43+
use uv_pep440::{VersionSpecifier, VersionSpecifiers};
4544
pub use verbatim_url::{
4645
expand_env_vars, split_scheme, strip_host, Scheme, VerbatimUrl, VerbatimUrlError,
4746
};
@@ -207,21 +206,6 @@ impl<T: Pep508Url> Requirement<T> {
207206
self.marker.evaluate(env, extras)
208207
}
209208

210-
/// Returns whether the requirement would be satisfied, independent of environment markers, i.e.
211-
/// if there is potentially an environment that could activate this requirement.
212-
///
213-
/// Note that unlike [`Self::evaluate_markers`] this does not perform any checks for bogus
214-
/// expressions but will simply return true. As caller you should separately perform a check
215-
/// with an environment and forward all warnings.
216-
pub fn evaluate_extras_and_python_version(
217-
&self,
218-
extras: &HashSet<ExtraName>,
219-
python_versions: &[Version],
220-
) -> bool {
221-
self.marker
222-
.evaluate_extras_and_python_version(extras, python_versions)
223-
}
224-
225209
/// Return the requirement with an additional marker added, to require the given extra.
226210
///
227211
/// For example, given `flask >= 2.0.2`, calling `with_extra_marker("dotenv")` would return

crates/uv-pep508/src/marker/algebra.rs

+37-27
Original file line numberDiff line numberDiff line change
@@ -158,44 +158,54 @@ impl InternerGuard<'_> {
158158
/// Returns a decision node for a single marker expression.
159159
pub(crate) fn expression(&mut self, expr: MarkerExpression) -> NodeId {
160160
let (var, children) = match expr {
161-
// Normalize `python_version` markers to `python_full_version` nodes.
162-
MarkerExpression::Version {
163-
key: MarkerValueVersion::PythonVersion,
164-
specifier,
165-
} => match python_version_to_full_version(normalize_specifier(specifier)) {
166-
Ok(specifier) => (
167-
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
161+
// A variable representing the output of a version key. Edges correspond
162+
// to disjoint version ranges.
163+
MarkerExpression::Version { key, specifier } => match key {
164+
MarkerValueVersion::ImplementationVersion => (
165+
Variable::Version(LoweredMarkerValueVersion::ImplementationVersion),
168166
Edges::from_specifier(specifier),
169167
),
170-
Err(node) => return node,
171-
},
172-
MarkerExpression::VersionIn {
173-
key: MarkerValueVersion::PythonVersion,
174-
versions,
175-
negated,
176-
} => match Edges::from_python_versions(versions, negated) {
177-
Ok(edges) => (
168+
MarkerValueVersion::PythonFullVersion => (
178169
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
179-
edges,
170+
Edges::from_specifier(specifier),
180171
),
181-
Err(node) => return node,
172+
// Normalize `python_version` markers to `python_full_version` nodes.
173+
MarkerValueVersion::PythonVersion => {
174+
match python_version_to_full_version(normalize_specifier(specifier)) {
175+
Ok(specifier) => (
176+
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
177+
Edges::from_specifier(specifier),
178+
),
179+
Err(node) => return node,
180+
}
181+
}
182182
},
183183
// A variable representing the output of a version key. Edges correspond
184184
// to disjoint version ranges.
185-
MarkerExpression::Version { key, specifier } => (
186-
Variable::Version(key.into()),
187-
Edges::from_specifier(specifier),
188-
),
189-
// A variable representing the output of a version key. Edges correspond
190-
// to disjoint version ranges.
191185
MarkerExpression::VersionIn {
192186
key,
193187
versions,
194188
negated,
195-
} => (
196-
Variable::Version(key.into()),
197-
Edges::from_versions(&versions, negated),
198-
),
189+
} => match key {
190+
MarkerValueVersion::ImplementationVersion => (
191+
Variable::Version(LoweredMarkerValueVersion::ImplementationVersion),
192+
Edges::from_versions(&versions, negated),
193+
),
194+
MarkerValueVersion::PythonFullVersion => (
195+
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
196+
Edges::from_versions(&versions, negated),
197+
),
198+
// Normalize `python_version` markers to `python_full_version` nodes.
199+
MarkerValueVersion::PythonVersion => {
200+
match Edges::from_python_versions(versions, negated) {
201+
Ok(edges) => (
202+
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
203+
edges,
204+
),
205+
Err(node) => return node,
206+
}
207+
}
208+
},
199209
// The `in` and `contains` operators are a bit different than other operators.
200210
// In particular, they do not represent a particular value for the corresponding
201211
// variable, and can overlap. For example, `'nux' in os_name` and `os_name == 'Linux'`

crates/uv-pep508/src/marker/environment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impl MarkerEnvironment {
3939
&self.implementation_version().version
4040
}
4141
LoweredMarkerValueVersion::PythonFullVersion => &self.python_full_version().version,
42-
LoweredMarkerValueVersion::PythonVersion => &self.python_version().version,
4342
}
4443
}
4544

crates/uv-pep508/src/marker/lowering.rs

-14
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,13 @@ pub enum LoweredMarkerValueVersion {
1212
ImplementationVersion,
1313
/// `python_full_version`
1414
PythonFullVersion,
15-
/// `python_version`
16-
PythonVersion,
1715
}
1816

1917
impl Display for LoweredMarkerValueVersion {
2018
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2119
match self {
2220
Self::ImplementationVersion => f.write_str("implementation_version"),
2321
Self::PythonFullVersion => f.write_str("python_full_version"),
24-
Self::PythonVersion => f.write_str("python_version"),
25-
}
26-
}
27-
}
28-
29-
impl From<MarkerValueVersion> for LoweredMarkerValueVersion {
30-
fn from(value: MarkerValueVersion) -> Self {
31-
match value {
32-
MarkerValueVersion::ImplementationVersion => Self::ImplementationVersion,
33-
MarkerValueVersion::PythonFullVersion => Self::PythonFullVersion,
34-
MarkerValueVersion::PythonVersion => Self::PythonVersion,
3522
}
3623
}
3724
}
@@ -41,7 +28,6 @@ impl From<LoweredMarkerValueVersion> for MarkerValueVersion {
4128
match value {
4229
LoweredMarkerValueVersion::ImplementationVersion => Self::ImplementationVersion,
4330
LoweredMarkerValueVersion::PythonFullVersion => Self::PythonFullVersion,
44-
LoweredMarkerValueVersion::PythonVersion => Self::PythonVersion,
4531
}
4632
}
4733
}

crates/uv-pep508/src/marker/tree.rs

-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cmp::Ordering;
2-
use std::collections::HashSet;
32
use std::fmt::{self, Display, Formatter};
43
use std::ops::{Bound, Deref};
54
use std::str::FromStr;
@@ -922,49 +921,6 @@ impl MarkerTree {
922921
false
923922
}
924923

925-
/// Checks if the requirement should be activated with the given set of active extras and a set
926-
/// of possible python versions (from `requires-python`) without evaluating the remaining
927-
/// environment markers, i.e. if there is potentially an environment that could activate this
928-
/// requirement.
929-
///
930-
/// Note that unlike [`Self::evaluate`] this does not perform any checks for bogus expressions but
931-
/// will simply return true. As caller you should separately perform a check with an environment
932-
/// and forward all warnings.
933-
pub fn evaluate_extras_and_python_version(
934-
&self,
935-
extras: &HashSet<ExtraName>,
936-
python_versions: &[Version],
937-
) -> bool {
938-
match self.kind() {
939-
MarkerTreeKind::True => true,
940-
MarkerTreeKind::False => false,
941-
MarkerTreeKind::Version(marker) => marker.edges().any(|(range, tree)| {
942-
if marker.key() == LoweredMarkerValueVersion::PythonVersion {
943-
if !python_versions
944-
.iter()
945-
.any(|version| range.contains(version))
946-
{
947-
return false;
948-
}
949-
}
950-
951-
tree.evaluate_extras_and_python_version(extras, python_versions)
952-
}),
953-
MarkerTreeKind::String(marker) => marker
954-
.children()
955-
.any(|(_, tree)| tree.evaluate_extras_and_python_version(extras, python_versions)),
956-
MarkerTreeKind::In(marker) => marker
957-
.children()
958-
.any(|(_, tree)| tree.evaluate_extras_and_python_version(extras, python_versions)),
959-
MarkerTreeKind::Contains(marker) => marker
960-
.children()
961-
.any(|(_, tree)| tree.evaluate_extras_and_python_version(extras, python_versions)),
962-
MarkerTreeKind::Extra(marker) => marker
963-
.edge(extras.contains(marker.name().extra()))
964-
.evaluate_extras_and_python_version(extras, python_versions),
965-
}
966-
}
967-
968924
/// Checks if the requirement should be activated with the given set of active extras without evaluating
969925
/// the remaining environment markers, i.e. if there is potentially an environment that could activate this
970926
/// requirement.

crates/uv-resolver/src/marker.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pub(crate) fn requires_python(tree: &MarkerTree) -> Option<RequiresPythonRange>
1010
match tree.kind() {
1111
MarkerTreeKind::True | MarkerTreeKind::False => {}
1212
MarkerTreeKind::Version(marker) => match marker.key() {
13-
LoweredMarkerValueVersion::PythonVersion
14-
| LoweredMarkerValueVersion::PythonFullVersion => {
13+
LoweredMarkerValueVersion::PythonFullVersion => {
1514
for (range, tree) in marker.edges() {
1615
if !tree.is_false() {
1716
markers.push(range.clone());

0 commit comments

Comments
 (0)