Skip to content

Commit f3afff9

Browse files
committed
Add support for HTML indexes
1 parent 9e6cb70 commit f3afff9

File tree

11 files changed

+465
-19
lines changed

11 files changed

+465
-19
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ target-lexicon = { version = "0.12.12" }
7575
tempfile = { version = "3.8.1" }
7676
textwrap = { version = "0.15.2" }
7777
thiserror = { version = "1.0.50" }
78+
tl = { version = "0.7.7" }
7879
tokio = { version = "1.33.0", features = ["rt-multi-thread"] }
7980
tokio-util = { version = "0.7.10", features = ["compat"] }
8081
toml = { version = "0.8.6" }

crates/distribution-filename/src/source_dist.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use thiserror::Error;
88
use pep440_rs::Version;
99
use puffin_normalize::{InvalidNameError, PackageName};
1010

11-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11+
#[derive(Clone, Debug, PartialEq, Eq)]
12+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1213
pub enum SourceDistExtension {
1314
Zip,
1415
TarGz,

crates/puffin-cli/tests/pip_compile.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,3 +2701,42 @@ fn cache_errors_are_non_fatal() -> Result<()> {
27012701
Ok(())
27022702
}
27032703
}
2704+
2705+
/// Resolve a distribution from an HTML-only registry.
2706+
#[test]
2707+
fn compile_html() -> Result<()> {
2708+
let temp_dir = TempDir::new()?;
2709+
let cache_dir = TempDir::new()?;
2710+
let venv = create_venv_py312(&temp_dir, &cache_dir);
2711+
2712+
let requirements_in = temp_dir.child("requirements.in");
2713+
requirements_in.write_str("jinja2<=3.1.2")?;
2714+
2715+
insta::with_settings!({
2716+
filters => INSTA_FILTERS.to_vec()
2717+
}, {
2718+
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
2719+
.arg("pip-compile")
2720+
.arg("requirements.in")
2721+
.arg("--cache-dir")
2722+
.arg(cache_dir.path())
2723+
.arg("--index-url")
2724+
.arg("https://download.pytorch.org/whl")
2725+
.env("VIRTUAL_ENV", venv.as_os_str())
2726+
.current_dir(&temp_dir), @r###"
2727+
success: true
2728+
exit_code: 0
2729+
----- stdout -----
2730+
# This file was autogenerated by Puffin v0.0.1 via the following command:
2731+
# puffin pip-compile requirements.in --cache-dir [CACHE_DIR]
2732+
jinja2==3.1.2
2733+
markupsafe==2.1.3
2734+
# via jinja2
2735+
2736+
----- stderr -----
2737+
Resolved 2 packages in [TIME]
2738+
"###);
2739+
});
2740+
2741+
Ok(())
2742+
}

crates/puffin-client/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.1"
44
edition = "2021"
55

66
[dependencies]
7-
distribution-filename = { path = "../distribution-filename" }
7+
distribution-filename = { path = "../distribution-filename", features = ["serde"] }
88
distribution-types = { path = "../distribution-types" }
99
install-wheel-rs = { path = "../install-wheel-rs" }
1010
pep440_rs = { path = "../pep440-rs" }
@@ -28,6 +28,7 @@ serde_json = { workspace = true }
2828
sha2 = { workspace = true }
2929
tempfile = { workspace = true }
3030
thiserror = { workspace = true }
31+
tl = { workspace = true }
3132
tokio = { workspace = true, features = ["fs"] }
3233
tokio-util = { workspace = true }
3334
tracing = { workspace = true }
@@ -37,4 +38,5 @@ url = { workspace = true }
3738
pep508_rs = { path = "../pep508-rs" }
3839

3940
anyhow = { workspace = true }
41+
insta = { version = "1.34.0" }
4042
tokio = { workspace = true, features = ["fs", "macros"] }

crates/puffin-client/src/error.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use async_zip::error::ZipError;
55
use thiserror::Error;
66
use url::Url;
77

8+
use crate::html;
89
use distribution_filename::{WheelFilename, WheelFilenameError};
910
use puffin_normalize::PackageName;
1011

@@ -49,6 +50,9 @@ pub enum Error {
4950
#[error("Received some unexpected JSON from {url}")]
5051
BadJson { source: serde_json::Error, url: Url },
5152

53+
#[error("Received some unexpected HTML from {url}")]
54+
BadHtml { source: html::Error, url: Url },
55+
5256
#[error(transparent)]
5357
AsyncHttpRangeReader(#[from] AsyncHttpRangeReaderError),
5458

@@ -82,10 +86,23 @@ pub enum Error {
8286
/// An [`io::Error`] with a filename attached
8387
#[error(transparent)]
8488
Persist(#[from] tempfile::PersistError),
89+
90+
#[error("Missing `Content-Type` header for {0}")]
91+
MissingContentType(Url),
92+
93+
#[error("Invalid `Content-Type` header for {0}")]
94+
InvalidContentTypeHeader(Url, #[source] http::header::ToStrError),
95+
96+
#[error("Unsupported `Content-Type` \"{1}\" for {0}")]
97+
UnsupportedMediaType(Url, String),
8598
}
8699

87100
impl Error {
88-
pub fn from_json_err(err: serde_json::Error, url: Url) -> Self {
101+
pub(crate) fn from_json_err(err: serde_json::Error, url: Url) -> Self {
89102
Self::BadJson { source: err, url }
90103
}
104+
105+
pub(crate) fn from_html_err(err: html::Error, url: Url) -> Self {
106+
Self::BadHtml { source: err, url }
107+
}
91108
}

0 commit comments

Comments
 (0)