diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index 8772f64fb9a..224f0cdf8cb 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -5446,8 +5446,7 @@ enum GitSourceKind { } /// Inspired by: -#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)] -#[serde(rename_all = "kebab-case")] +#[derive(Clone, Debug, PartialEq, Eq)] struct SourceDistMetadata { /// A hash of the source distribution. hash: Option, @@ -5456,7 +5455,6 @@ struct SourceDistMetadata { /// This is only present for source distributions that come from registries. size: Option, /// The upload time of the source distribution. - #[serde(alias = "upload_time")] upload_time: Option, } @@ -5464,25 +5462,62 @@ struct SourceDistMetadata { /// locked against was found. The location does not need to exist in the /// future, so this should be treated as only a hint to where to look /// and/or recording where the source dist file originally came from. -#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)] -#[serde(from = "SourceDistWire")] +#[derive(Clone, Debug, PartialEq, Eq)] enum SourceDist { Url { url: UrlString, - #[serde(flatten)] metadata: SourceDistMetadata, }, Path { path: Box, - #[serde(flatten)] metadata: SourceDistMetadata, }, Metadata { - #[serde(flatten)] metadata: SourceDistMetadata, }, } +impl<'de> serde::Deserialize<'de> for SourceDist { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + #[derive(serde::Deserialize)] + #[serde(rename_all = "kebab-case")] + struct Fields { + url: Option, + path: Option, + hash: Option, + size: Option, + #[serde(alias = "upload_time")] + upload_time: Option, + } + + let Fields { + url, + path, + hash, + size, + upload_time, + } = serde::Deserialize::deserialize(deserializer)?; + + let metadata = SourceDistMetadata { + hash, + size, + upload_time, + }; + + Ok(match (url, path) { + (Some(url), _) => Self::Url { url, metadata }, + (None, Some(path)) => Self::Path { + path: path.into(), + metadata, + }, + (None, None) => Self::Metadata { metadata }, + }) + } +} + impl SourceDist { fn filename(&self) -> Option> { match self { @@ -5741,38 +5776,6 @@ impl SourceDist { } } -#[derive(Clone, Debug, serde::Deserialize)] -#[serde(untagged, rename_all = "kebab-case")] -enum SourceDistWire { - Url { - url: UrlString, - #[serde(flatten)] - metadata: SourceDistMetadata, - }, - Path { - path: PortablePathBuf, - #[serde(flatten)] - metadata: SourceDistMetadata, - }, - Metadata { - #[serde(flatten)] - metadata: SourceDistMetadata, - }, -} - -impl From for SourceDist { - fn from(wire: SourceDistWire) -> Self { - match wire { - SourceDistWire::Url { url, metadata } => Self::Url { url, metadata }, - SourceDistWire::Path { path, metadata } => Self::Path { - path: path.into(), - metadata, - }, - SourceDistWire::Metadata { metadata } => Self::Metadata { metadata }, - } - } -} - impl From for GitSourceKind { fn from(value: GitReference) -> Self { match value {