diff --git a/crates/distribution-types/src/index_url.rs b/crates/distribution-types/src/index_url.rs index 1e7e94ae0..42c105ccd 100644 --- a/crates/distribution-types/src/index_url.rs +++ b/crates/distribution-types/src/index_url.rs @@ -6,7 +6,6 @@ use std::str::FromStr; use itertools::Either; use once_cell::sync::Lazy; -use serde::{Deserialize, Serialize}; use url::Url; use pep508_rs::{expand_env_vars, split_scheme, strip_host, Scheme, VerbatimUrl}; @@ -110,7 +109,7 @@ impl serde::ser::Serialize for IndexUrl { where S: serde::ser::Serializer, { - self.verbatim().serialize(serializer) + self.to_string().serialize(serializer) } } @@ -159,7 +158,7 @@ impl Deref for IndexUrl { /// A directory with distributions or a URL to an HTML file with a flat listing of distributions. /// /// Also known as `--find-links`. -#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, Eq, PartialEq)] pub enum FlatIndexLocation { Path(PathBuf), Url(Url), @@ -185,6 +184,25 @@ impl schemars::JsonSchema for FlatIndexLocation { } } +impl serde::ser::Serialize for FlatIndexLocation { + fn serialize(&self, serializer: S) -> Result + where + S: serde::ser::Serializer, + { + self.to_string().serialize(serializer) + } +} + +impl<'de> serde::de::Deserialize<'de> for FlatIndexLocation { + fn deserialize(deserializer: D) -> Result + where + D: serde::de::Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + FlatIndexLocation::from_str(&s).map_err(serde::de::Error::custom) + } +} + impl FromStr for FlatIndexLocation { type Err = url::ParseError; diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index e8b927865..76f4793c1 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -8653,6 +8653,36 @@ fn resolve_configuration() -> Result<()> { "### ); + // Write out a `--find-links` entry. + // Add an extra index URL entry to the `pyproject.toml` file. + pyproject.write_str(indoc::indoc! {r#" + [project] + name = "example" + version = "0.0.0" + + [tool.uv.pip] + no-index = true + find-links = ["https://download.pytorch.org/whl/torch_stable.html"] + "#})?; + + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("tqdm")?; + + uv_snapshot!(context.compile() + .arg("requirements.in"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in + tqdm==4.66.2 + # via -r requirements.in + + ----- stderr ----- + Resolved 1 package in [TIME] + "### + ); + Ok(()) }