Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 43 additions & 40 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5446,8 +5446,7 @@ enum GitSourceKind {
}

/// Inspired by: <https://discuss.python.org/t/lock-files-again-but-this-time-w-sdists/46593>
#[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<Hash>,
Expand All @@ -5456,33 +5455,69 @@ struct SourceDistMetadata {
/// This is only present for source distributions that come from registries.
size: Option<u64>,
/// The upload time of the source distribution.
#[serde(alias = "upload_time")]
upload_time: Option<Timestamp>,
}

/// A URL or file path where the source dist that was
/// 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<Path>,
#[serde(flatten)]
metadata: SourceDistMetadata,
},
Metadata {
#[serde(flatten)]
metadata: SourceDistMetadata,
},
}

impl<'de> serde::Deserialize<'de> for SourceDist {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Fields {
url: Option<UrlString>,
path: Option<PortablePathBuf>,
hash: Option<Hash>,
size: Option<u64>,
#[serde(alias = "upload_time")]
upload_time: Option<Timestamp>,
}

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<Cow<'_, str>> {
match self {
Expand Down Expand Up @@ -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<SourceDistWire> 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<GitReference> for GitSourceKind {
fn from(value: GitReference) -> Self {
match value {
Expand Down
Loading