From 4bf01ed33770d4f10793f32f63a6ed07f59ee97b Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 30 Oct 2024 10:20:56 +0100 Subject: [PATCH] Fix non-optional uv-pep440 features (#8693) --- crates/uv-pep440/src/version_specifier.rs | 36 ++++++++--------------- crates/uv-pep508/Cargo.toml | 1 - crates/uv-pep508/src/lib.rs | 3 ++ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/uv-pep440/src/version_specifier.rs b/crates/uv-pep440/src/version_specifier.rs index 56fa5f597..972e5faed 100644 --- a/crates/uv-pep440/src/version_specifier.rs +++ b/crates/uv-pep440/src/version_specifier.rs @@ -6,6 +6,7 @@ use crate::{ version, Operator, OperatorParseError, Version, VersionPattern, VersionPatternParseError, }; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "tracing")] use tracing::warn; /// Sorted version specifiers, such as `>=2.1,<3`. @@ -23,19 +24,12 @@ use tracing::warn; /// // VersionSpecifiers derefs into a list of specifiers /// assert_eq!(version_specifiers.iter().position(|specifier| *specifier.operator() == Operator::LessThan), Some(1)); /// ``` -#[derive( - Eq, - PartialEq, - Ord, - PartialOrd, - Debug, - Clone, - Hash, - rkyv::Archive, - rkyv::Deserialize, - rkyv::Serialize, +#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] +#[cfg_attr( + feature = "rkyv", + derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize) )] -#[rkyv(derive(Debug))] +#[cfg_attr(feature = "rkyv", rkyv(derive(Debug)))] pub struct VersionSpecifiers(Vec); impl std::ops::Deref for VersionSpecifiers { @@ -97,6 +91,7 @@ impl VersionSpecifiers { specifiers.push(VersionSpecifier::not_equals_star_version(prev.clone())); } _ => { + #[cfg(feature = "tracing")] warn!("Ignoring unsupported gap in `requires-python` version: {next:?} -> {lower:?}"); } } @@ -239,19 +234,12 @@ impl std::error::Error for VersionSpecifiersParseError {} /// let version_specifier = VersionSpecifier::from_str("== 1.*").unwrap(); /// assert!(version_specifier.contains(&version)); /// ``` -#[derive( - Eq, - Ord, - PartialEq, - PartialOrd, - Debug, - Clone, - Hash, - rkyv::Archive, - rkyv::Deserialize, - rkyv::Serialize, +#[derive(Eq, Ord, PartialEq, PartialOrd, Debug, Clone, Hash)] +#[cfg_attr( + feature = "rkyv", + derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize) )] -#[rkyv(derive(Debug))] +#[cfg_attr(feature = "rkyv", rkyv(derive(Debug)))] pub struct VersionSpecifier { /// ~=|==|!=|<=|>=|<|>|===, plus whether the version ended with a star pub(crate) operator: Operator, diff --git a/crates/uv-pep508/Cargo.toml b/crates/uv-pep508/Cargo.toml index f310fede9..0968cbc1c 100644 --- a/crates/uv-pep508/Cargo.toml +++ b/crates/uv-pep508/Cargo.toml @@ -32,7 +32,6 @@ regex = { workspace = true } rustc-hash = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive", "rc"] } -serde_json = { workspace = true, optional = true } smallvec = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true, optional = true } diff --git a/crates/uv-pep508/src/lib.rs b/crates/uv-pep508/src/lib.rs index ab0bc0299..ef02f502e 100644 --- a/crates/uv-pep508/src/lib.rs +++ b/crates/uv-pep508/src/lib.rs @@ -38,6 +38,9 @@ pub use origin::RequirementOrigin; #[cfg(feature = "non-pep508-extensions")] pub use unnamed::{UnnamedRequirement, UnnamedRequirementUrl}; pub use uv_normalize::{ExtraName, InvalidNameError, PackageName}; +/// Version and version specifiers used in requirements (reexport). +// https://github.com/konstin/pep508_rs/issues/19 +pub use uv_pep440; use uv_pep440::{Version, VersionSpecifier, VersionSpecifiers}; pub use verbatim_url::{ expand_env_vars, split_scheme, strip_host, Scheme, VerbatimUrl, VerbatimUrlError,