mirror of
https://github.com/astral-sh/uv
synced 2026-01-22 22:10:11 -05:00
Serialize Python requests for tools as canonicalized strings (#14109)
When working on support for reading global Python pins in tool operations, I noticed that we weren't using the canonicalized Python request in receipts — we were using the raw string provided by the user. Since we'll need to compare these values, we should be using the canonicalized string. The `Tool` and `ToolReceipt` types have been updated to hold a `PythonRequest` instead of a `String`, and `Serialize` was implemented for `PythonRequest` so canonicalization can happen at the edge instead of being the caller's responsibility.
This commit is contained in:
@@ -67,6 +67,26 @@ pub enum PythonRequest {
|
||||
Key(PythonDownloadRequest),
|
||||
}
|
||||
|
||||
impl<'a> serde::Deserialize<'a> for PythonRequest {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'a>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
Ok(PythonRequest::parse(&s))
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for PythonRequest {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let s = self.to_canonical_string();
|
||||
serializer.serialize_str(&s)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
|
||||
Reference in New Issue
Block a user