Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTML indexes #719

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ target-lexicon = { version = "0.12.12" }
tempfile = { version = "3.8.1" }
textwrap = { version = "0.15.2" }
thiserror = { version = "1.0.50" }
tl = { version = "0.7.7" }
tokio = { version = "1.33.0", features = ["rt-multi-thread"] }
tokio-util = { version = "0.7.10", features = ["compat"] }
toml = { version = "0.8.6" }
Expand Down
3 changes: 2 additions & 1 deletion crates/distribution-filename/src/source_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use thiserror::Error;
use pep440_rs::Version;
use puffin_normalize::{InvalidNameError, PackageName};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum SourceDistExtension {
Zip,
TarGz,
Expand Down
39 changes: 39 additions & 0 deletions crates/puffin-cli/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2701,3 +2701,42 @@ fn cache_errors_are_non_fatal() -> Result<()> {
Ok(())
}
}

/// Resolve a distribution from an HTML-only registry.
#[test]
fn compile_html() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = create_venv_py312(&temp_dir, &cache_dir);

let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("jinja2<=3.1.2")?;

insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
.arg("requirements.in")
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--index-url")
.arg("https://download.pytorch.org/whl")
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by Puffin v0.0.1 via the following command:
# puffin pip-compile requirements.in --cache-dir [CACHE_DIR]
jinja2==3.1.2
markupsafe==2.1.3
# via jinja2

----- stderr -----
Resolved 2 packages in [TIME]
"###);
});

Ok(())
}
4 changes: 3 additions & 1 deletion crates/puffin-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1"
edition = "2021"

[dependencies]
distribution-filename = { path = "../distribution-filename" }
distribution-filename = { path = "../distribution-filename", features = ["serde"] }
distribution-types = { path = "../distribution-types" }
install-wheel-rs = { path = "../install-wheel-rs" }
pep440_rs = { path = "../pep440-rs" }
Expand All @@ -28,6 +28,7 @@ serde_json = { workspace = true }
sha2 = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tl = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
tokio-util = { workspace = true }
tracing = { workspace = true }
Expand All @@ -37,4 +38,5 @@ url = { workspace = true }
pep508_rs = { path = "../pep508-rs" }

anyhow = { workspace = true }
insta = { version = "1.34.0" }
tokio = { workspace = true, features = ["fs", "macros"] }
19 changes: 18 additions & 1 deletion crates/puffin-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_zip::error::ZipError;
use thiserror::Error;
use url::Url;

use crate::html;
use distribution_filename::{WheelFilename, WheelFilenameError};
use puffin_normalize::PackageName;

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

#[error("Received some unexpected HTML from {url}")]
BadHtml { source: html::Error, url: Url },

#[error(transparent)]
AsyncHttpRangeReader(#[from] AsyncHttpRangeReaderError),

Expand Down Expand Up @@ -82,10 +86,23 @@ pub enum Error {
/// An [`io::Error`] with a filename attached
#[error(transparent)]
Persist(#[from] tempfile::PersistError),

#[error("Missing `Content-Type` header for {0}")]
MissingContentType(Url),

#[error("Invalid `Content-Type` header for {0}")]
InvalidContentTypeHeader(Url, #[source] http::header::ToStrError),

#[error("Unsupported `Content-Type` \"{1}\" for {0}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should tell the user which content types we support

UnsupportedMediaType(Url, String),
}

impl Error {
pub fn from_json_err(err: serde_json::Error, url: Url) -> Self {
pub(crate) fn from_json_err(err: serde_json::Error, url: Url) -> Self {
Self::BadJson { source: err, url }
}

pub(crate) fn from_html_err(err: html::Error, url: Url) -> Self {
Self::BadHtml { source: err, url }
}
}
Loading