mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-02 06:51:14 +00:00
Add serialization and deserialization for --find-links
(#3619)
## Summary Closes https://github.com/astral-sh/uv/issues/3617.
This commit is contained in:
parent
018a7150d6
commit
a735f6d80c
2 changed files with 51 additions and 3 deletions
|
@ -6,7 +6,6 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use pep508_rs::{expand_env_vars, split_scheme, strip_host, Scheme, VerbatimUrl};
|
use pep508_rs::{expand_env_vars, split_scheme, strip_host, Scheme, VerbatimUrl};
|
||||||
|
@ -110,7 +109,7 @@ impl serde::ser::Serialize for IndexUrl {
|
||||||
where
|
where
|
||||||
S: serde::ser::Serializer,
|
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.
|
/// A directory with distributions or a URL to an HTML file with a flat listing of distributions.
|
||||||
///
|
///
|
||||||
/// Also known as `--find-links`.
|
/// Also known as `--find-links`.
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||||
pub enum FlatIndexLocation {
|
pub enum FlatIndexLocation {
|
||||||
Path(PathBuf),
|
Path(PathBuf),
|
||||||
Url(Url),
|
Url(Url),
|
||||||
|
@ -185,6 +184,25 @@ impl schemars::JsonSchema for FlatIndexLocation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl serde::ser::Serialize for FlatIndexLocation {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::ser::Serializer,
|
||||||
|
{
|
||||||
|
self.to_string().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> serde::de::Deserialize<'de> for FlatIndexLocation {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<FlatIndexLocation, D::Error>
|
||||||
|
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 {
|
impl FromStr for FlatIndexLocation {
|
||||||
type Err = url::ParseError;
|
type Err = url::ParseError;
|
||||||
|
|
||||||
|
|
|
@ -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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue