mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 12:09:12 +00:00
Make marker enums Copy
(#9305)
This commit is contained in:
parent
5e48819dbb
commit
3143494ddb
5 changed files with 38 additions and 38 deletions
|
@ -33,7 +33,7 @@ struct MarkerEnvironmentInner {
|
|||
|
||||
impl MarkerEnvironment {
|
||||
/// Returns of the PEP 440 version typed value of the key in the current environment
|
||||
pub fn get_version(&self, key: &MarkerValueVersion) -> &Version {
|
||||
pub fn get_version(&self, key: MarkerValueVersion) -> &Version {
|
||||
match key {
|
||||
MarkerValueVersion::ImplementationVersion => &self.implementation_version().version,
|
||||
MarkerValueVersion::PythonFullVersion => &self.python_full_version().version,
|
||||
|
@ -42,7 +42,7 @@ impl MarkerEnvironment {
|
|||
}
|
||||
|
||||
/// Returns of the stringly typed value of the key in the current environment
|
||||
pub fn get_string(&self, key: &MarkerValueString) -> &str {
|
||||
pub fn get_string(&self, key: MarkerValueString) -> &str {
|
||||
match key {
|
||||
MarkerValueString::ImplementationName => self.implementation_name(),
|
||||
MarkerValueString::OsName | MarkerValueString::OsNameDeprecated => self.os_name(),
|
||||
|
|
|
@ -150,12 +150,12 @@ pub(crate) fn parse_marker_key_op_value<T: Pep508Url>(
|
|||
};
|
||||
|
||||
// Check for `in` and `not in` expressions
|
||||
if let Some(expr) = parse_version_in_expr(key.clone(), operator, &value, reporter) {
|
||||
if let Some(expr) = parse_version_in_expr(key, operator, &value, reporter) {
|
||||
return Ok(Some(expr));
|
||||
}
|
||||
|
||||
// Otherwise, it's a normal version expression
|
||||
parse_version_expr(key.clone(), operator, &value, reporter)
|
||||
parse_version_expr(key, operator, &value, reporter)
|
||||
}
|
||||
// The only sound choice for this is `<env key> <op> <string>`
|
||||
MarkerValue::MarkerEnvString(key) => {
|
||||
|
@ -215,7 +215,7 @@ pub(crate) fn parse_marker_key_op_value<T: Pep508Url>(
|
|||
match r_value {
|
||||
// The only sound choice for this is `<quoted PEP 440 version> <version op>` <version key>
|
||||
MarkerValue::MarkerEnvVersion(key) => {
|
||||
parse_inverted_version_expr(&l_string, operator, key.clone(), reporter)
|
||||
parse_inverted_version_expr(&l_string, operator, key, reporter)
|
||||
}
|
||||
// '...' == <env key>
|
||||
MarkerValue::MarkerEnvString(key) => Some(MarkerExpression::String {
|
||||
|
|
|
@ -51,7 +51,7 @@ fn collect_dnf(
|
|||
let current = path.len();
|
||||
for version in excluded {
|
||||
path.push(MarkerExpression::Version {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
specifier: VersionSpecifier::not_equals_version(version.clone()),
|
||||
});
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ fn collect_dnf(
|
|||
// Detect whether the range for this edge can be simplified as a star inequality.
|
||||
if let Some(specifier) = star_range_inequality(&range) {
|
||||
path.push(MarkerExpression::Version {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
specifier,
|
||||
});
|
||||
|
||||
|
@ -77,7 +77,7 @@ fn collect_dnf(
|
|||
let current = path.len();
|
||||
for specifier in VersionSpecifier::from_release_only_bounds(bounds) {
|
||||
path.push(MarkerExpression::Version {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
specifier,
|
||||
});
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ fn collect_dnf(
|
|||
let current = path.len();
|
||||
for value in excluded {
|
||||
path.push(MarkerExpression::String {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
operator: MarkerOperator::NotEqual,
|
||||
value: value.clone(),
|
||||
});
|
||||
|
@ -109,7 +109,7 @@ fn collect_dnf(
|
|||
let current = path.len();
|
||||
for (operator, value) in MarkerOperator::from_bounds(bounds) {
|
||||
path.push(MarkerExpression::String {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
operator,
|
||||
value: value.clone(),
|
||||
});
|
||||
|
@ -129,7 +129,7 @@ fn collect_dnf(
|
|||
};
|
||||
|
||||
let expr = MarkerExpression::String {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
value: marker.value().to_owned(),
|
||||
operator,
|
||||
};
|
||||
|
@ -148,7 +148,7 @@ fn collect_dnf(
|
|||
};
|
||||
|
||||
let expr = MarkerExpression::String {
|
||||
key: marker.key().clone(),
|
||||
key: marker.key(),
|
||||
value: marker.value().to_owned(),
|
||||
operator,
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ use super::algebra::{Edges, NodeId, Variable, INTERNER};
|
|||
use super::simplify;
|
||||
|
||||
/// Ways in which marker evaluation can fail
|
||||
#[derive(Debug, Eq, Hash, Ord, PartialOrd, PartialEq, Clone, Copy)]
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
pub enum MarkerWarningKind {
|
||||
/// Using an old name from PEP 345 instead of the modern equivalent
|
||||
/// <https://peps.python.org/pep-0345/#environment-markers>
|
||||
|
@ -39,7 +39,7 @@ pub enum MarkerWarningKind {
|
|||
}
|
||||
|
||||
/// Those environment markers with a PEP 440 version as value such as `python_version`
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum MarkerValueVersion {
|
||||
/// `implementation_version`
|
||||
|
@ -61,7 +61,7 @@ impl Display for MarkerValueVersion {
|
|||
}
|
||||
|
||||
/// Those environment markers with an arbitrary string as value such as `sys_platform`
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||
pub enum MarkerValueString {
|
||||
/// `implementation_name`
|
||||
ImplementationName,
|
||||
|
@ -754,7 +754,7 @@ impl MarkerTree {
|
|||
};
|
||||
MarkerTreeKind::Version(VersionMarkerTree {
|
||||
id: self.0,
|
||||
key: key.clone(),
|
||||
key: *key,
|
||||
map,
|
||||
})
|
||||
}
|
||||
|
@ -764,7 +764,7 @@ impl MarkerTree {
|
|||
};
|
||||
MarkerTreeKind::String(StringMarkerTree {
|
||||
id: self.0,
|
||||
key: key.clone(),
|
||||
key: *key,
|
||||
map,
|
||||
})
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ impl MarkerTree {
|
|||
unreachable!()
|
||||
};
|
||||
MarkerTreeKind::In(InMarkerTree {
|
||||
key: key.clone(),
|
||||
key: *key,
|
||||
value,
|
||||
high: high.negate(self.0),
|
||||
low: low.negate(self.0),
|
||||
|
@ -784,7 +784,7 @@ impl MarkerTree {
|
|||
unreachable!()
|
||||
};
|
||||
MarkerTreeKind::Contains(ContainsMarkerTree {
|
||||
key: key.clone(),
|
||||
key: *key,
|
||||
value,
|
||||
high: high.negate(self.0),
|
||||
low: low.negate(self.0),
|
||||
|
@ -932,7 +932,7 @@ impl MarkerTree {
|
|||
MarkerTreeKind::True => true,
|
||||
MarkerTreeKind::False => false,
|
||||
MarkerTreeKind::Version(marker) => marker.edges().any(|(range, tree)| {
|
||||
if *marker.key() == MarkerValueVersion::PythonVersion {
|
||||
if marker.key() == MarkerValueVersion::PythonVersion {
|
||||
if !python_versions
|
||||
.iter()
|
||||
.any(|version| range.contains(version))
|
||||
|
@ -1423,8 +1423,8 @@ pub struct VersionMarkerTree<'a> {
|
|||
|
||||
impl VersionMarkerTree<'_> {
|
||||
/// The key for this node.
|
||||
pub fn key(&self) -> &MarkerValueVersion {
|
||||
&self.key
|
||||
pub fn key(&self) -> MarkerValueVersion {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// The edges of this node, corresponding to possible output ranges of the given variable.
|
||||
|
@ -1444,7 +1444,7 @@ impl PartialOrd for VersionMarkerTree<'_> {
|
|||
impl Ord for VersionMarkerTree<'_> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.key()
|
||||
.cmp(other.key())
|
||||
.cmp(&other.key())
|
||||
.then_with(|| self.edges().cmp(other.edges()))
|
||||
}
|
||||
}
|
||||
|
@ -1459,8 +1459,8 @@ pub struct StringMarkerTree<'a> {
|
|||
|
||||
impl StringMarkerTree<'_> {
|
||||
/// The key for this node.
|
||||
pub fn key(&self) -> &MarkerValueString {
|
||||
&self.key
|
||||
pub fn key(&self) -> MarkerValueString {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// The edges of this node, corresponding to possible output ranges of the given variable.
|
||||
|
@ -1480,7 +1480,7 @@ impl PartialOrd for StringMarkerTree<'_> {
|
|||
impl Ord for StringMarkerTree<'_> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.key()
|
||||
.cmp(other.key())
|
||||
.cmp(&other.key())
|
||||
.then_with(|| self.children().cmp(other.children()))
|
||||
}
|
||||
}
|
||||
|
@ -1496,8 +1496,8 @@ pub struct InMarkerTree<'a> {
|
|||
|
||||
impl InMarkerTree<'_> {
|
||||
/// The key (LHS) for this expression.
|
||||
pub fn key(&self) -> &MarkerValueString {
|
||||
&self.key
|
||||
pub fn key(&self) -> MarkerValueString {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// The value (RHS) for this expression.
|
||||
|
@ -1529,7 +1529,7 @@ impl PartialOrd for InMarkerTree<'_> {
|
|||
impl Ord for InMarkerTree<'_> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.key()
|
||||
.cmp(other.key())
|
||||
.cmp(&other.key())
|
||||
.then_with(|| self.value().cmp(other.value()))
|
||||
.then_with(|| self.children().cmp(other.children()))
|
||||
}
|
||||
|
@ -1546,8 +1546,8 @@ pub struct ContainsMarkerTree<'a> {
|
|||
|
||||
impl ContainsMarkerTree<'_> {
|
||||
/// The key (LHS) for this expression.
|
||||
pub fn key(&self) -> &MarkerValueString {
|
||||
&self.key
|
||||
pub fn key(&self) -> MarkerValueString {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// The value (RHS) for this expression.
|
||||
|
@ -1579,7 +1579,7 @@ impl PartialOrd for ContainsMarkerTree<'_> {
|
|||
impl Ord for ContainsMarkerTree<'_> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.key()
|
||||
.cmp(other.key())
|
||||
.cmp(&other.key())
|
||||
.then_with(|| self.value().cmp(other.value()))
|
||||
.then_with(|| self.children().cmp(other.children()))
|
||||
}
|
||||
|
|
|
@ -636,25 +636,25 @@ impl ResolverOutput {
|
|||
MarkerTreeKind::True => {}
|
||||
MarkerTreeKind::False => {}
|
||||
MarkerTreeKind::Version(marker) => {
|
||||
set.insert(MarkerParam::Version(marker.key().clone()));
|
||||
set.insert(MarkerParam::Version(marker.key()));
|
||||
for (_, tree) in marker.edges() {
|
||||
add_marker_params_from_tree(&tree, set);
|
||||
}
|
||||
}
|
||||
MarkerTreeKind::String(marker) => {
|
||||
set.insert(MarkerParam::String(marker.key().clone()));
|
||||
set.insert(MarkerParam::String(marker.key()));
|
||||
for (_, tree) in marker.children() {
|
||||
add_marker_params_from_tree(&tree, set);
|
||||
}
|
||||
}
|
||||
MarkerTreeKind::In(marker) => {
|
||||
set.insert(MarkerParam::String(marker.key().clone()));
|
||||
set.insert(MarkerParam::String(marker.key()));
|
||||
for (_, tree) in marker.children() {
|
||||
add_marker_params_from_tree(&tree, set);
|
||||
}
|
||||
}
|
||||
MarkerTreeKind::Contains(marker) => {
|
||||
set.insert(MarkerParam::String(marker.key().clone()));
|
||||
set.insert(MarkerParam::String(marker.key()));
|
||||
for (_, tree) in marker.children() {
|
||||
add_marker_params_from_tree(&tree, set);
|
||||
}
|
||||
|
@ -715,14 +715,14 @@ impl ResolverOutput {
|
|||
for marker_param in seen_marker_values {
|
||||
let expr = match marker_param {
|
||||
MarkerParam::Version(value_version) => {
|
||||
let from_env = marker_env.get_version(&value_version);
|
||||
let from_env = marker_env.get_version(value_version);
|
||||
MarkerExpression::Version {
|
||||
key: value_version,
|
||||
specifier: VersionSpecifier::equals_version(from_env.clone()),
|
||||
}
|
||||
}
|
||||
MarkerParam::String(value_string) => {
|
||||
let from_env = marker_env.get_string(&value_string);
|
||||
let from_env = marker_env.get_string(value_string);
|
||||
MarkerExpression::String {
|
||||
key: value_string,
|
||||
operator: MarkerOperator::Equal,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue