diff --git a/crates/distribution-types/src/index_url.rs b/crates/distribution-types/src/index_url.rs index 3467ccf41..1fee4e0bf 100644 --- a/crates/distribution-types/src/index_url.rs +++ b/crates/distribution-types/src/index_url.rs @@ -20,7 +20,7 @@ static DEFAULT_INDEX_URL: Lazy = Lazy::new(|| IndexUrl::Pypi(VerbatimUrl::from_url(PYPI_URL.clone()))); /// The url of an index, newtype'd to avoid mixing it with file urls. -#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, Eq, PartialEq)] pub enum IndexUrl { Pypi(VerbatimUrl), Url(VerbatimUrl), @@ -100,6 +100,25 @@ impl FromStr for IndexUrl { } } +impl serde::ser::Serialize for IndexUrl { + fn serialize(&self, serializer: S) -> Result + where + S: serde::ser::Serializer, + { + self.verbatim().serialize(serializer) + } +} + +impl<'de> serde::de::Deserialize<'de> for IndexUrl { + fn deserialize(deserializer: D) -> Result + where + D: serde::de::Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + IndexUrl::from_str(&s).map_err(serde::de::Error::custom) + } +} + impl From for IndexUrl { fn from(url: VerbatimUrl) -> Self { if *url.raw() == *PYPI_URL { diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 2bcc70c17..b7589c845 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -8217,6 +8217,7 @@ fn resolve_configuration() -> Result<()> { [pip] resolution = "lowest-direct" generate-hashes = true + index-url = "https://pypi.org/simple" "#})?; let requirements_in = context.temp_dir.child("requirements.in"); @@ -8358,6 +8359,7 @@ fn resolve_configuration() -> Result<()> { [tool.uv.pip] resolution = "lowest-direct" generate-hashes = true + index-url = "https://pypi.org/simple" "#})?; // Resolution should use the lowest direct version, and generate hashes.