From d0435ef20afa4a4bee7b9d8d752e0e1b11634d97 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 20 May 2024 13:45:35 -0400 Subject: [PATCH] pep508: add `PartialOrd` and `Ord` implementations to `MarkerTree` Since we're adding a `Option` to `PubGrubPackage`, and since we just make `PubGrubPackage` implement `Ord`, it follows that we want `MarkerTree` to also implement `Ord`. --- crates/pep440-rs/src/version.rs | 12 +++++++++++- crates/pep440-rs/src/version_specifier.rs | 13 ++++++++++++- crates/pep508-rs/src/marker.rs | 14 +++++++------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/crates/pep440-rs/src/version.rs b/crates/pep440-rs/src/version.rs index 09f8d8def..6c851c980 100644 --- a/crates/pep440-rs/src/version.rs +++ b/crates/pep440-rs/src/version.rs @@ -15,7 +15,17 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; /// One of `~=` `==` `!=` `<=` `>=` `<` `>` `===` #[derive( - Eq, PartialEq, Debug, Hash, Clone, Copy, rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, + Eq, + Ord, + PartialEq, + PartialOrd, + Debug, + Hash, + Clone, + Copy, + rkyv::Archive, + rkyv::Deserialize, + rkyv::Serialize, )] #[archive(check_bytes)] #[archive_attr(derive(Debug, Eq, PartialEq, PartialOrd, Ord))] diff --git a/crates/pep440-rs/src/version_specifier.rs b/crates/pep440-rs/src/version_specifier.rs index 5de056699..7faf9f68a 100644 --- a/crates/pep440-rs/src/version_specifier.rs +++ b/crates/pep440-rs/src/version_specifier.rs @@ -250,7 +250,18 @@ impl std::error::Error for VersionSpecifiersParseError {} /// let version_specifier = VersionSpecifier::from_str("== 1.*").unwrap(); /// assert!(version_specifier.contains(&version)); /// ``` -#[derive(Eq, PartialEq, Debug, Clone, Hash, rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)] +#[derive( + Eq, + Ord, + PartialEq, + PartialOrd, + Debug, + Clone, + Hash, + rkyv::Archive, + rkyv::Deserialize, + rkyv::Serialize, +)] #[archive(check_bytes)] #[archive_attr(derive(Debug))] #[cfg_attr(feature = "pyo3", pyclass(get_all))] diff --git a/crates/pep508-rs/src/marker.rs b/crates/pep508-rs/src/marker.rs index d11a29c10..232cdd794 100644 --- a/crates/pep508-rs/src/marker.rs +++ b/crates/pep508-rs/src/marker.rs @@ -63,7 +63,7 @@ impl MarkerWarningKind { } /// Those environment markers with a PEP 440 version as value such as `python_version` -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[allow(clippy::enum_variant_names)] pub enum MarkerValueVersion { /// `implementation_version` @@ -85,7 +85,7 @@ impl Display for MarkerValueVersion { } /// Those environment markers with an arbitrary string as value such as `sys_platform` -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum MarkerValueString { /// `implementation_name` ImplementationName, @@ -142,7 +142,7 @@ impl Display for MarkerValueString { /// One of the predefined environment values /// /// -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum MarkerValue { /// Those environment markers with a PEP 440 version as value such as `python_version` MarkerEnvVersion(MarkerValueVersion), @@ -214,7 +214,7 @@ impl Display for MarkerValue { } /// How to compare key and value, such as by `==`, `>` or `not in` -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum MarkerOperator { /// `==` Equal, @@ -900,7 +900,7 @@ impl<'a> TryFrom> for MarkerEnvironment { } /// Represents one clause such as `python_version > "3.8"`. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[allow(missing_docs)] pub enum MarkerExpression { /// A version expression, e.g. ` `. @@ -943,7 +943,7 @@ pub enum MarkerExpression { } /// The operator for an extra expression, either '==' or '!='. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum ExtraOperator { /// `==` Equal, @@ -1529,7 +1529,7 @@ impl Display for MarkerExpression { } /// Represents one of the nested marker expressions with and/or/parentheses -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum MarkerTree { /// A simple expression such as `python_version > "3.8"` Expression(MarkerExpression),