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

Add support for HTML indexes #719

merged 1 commit into from
Dec 24, 2023

Conversation

charliermarsh
Copy link
Member

Summary

This PR adds support for HTML index responses (as with --index-url=https://download.pytorch.org/whl).

Closes #412.

@charliermarsh charliermarsh added the enhancement New feature or improvement to existing functionality label Dec 24, 2023
@charliermarsh charliermarsh force-pushed the charlie/html branch 4 times, most recently from fc8acef to f3afff9 Compare December 24, 2023 15:50
@charliermarsh charliermarsh enabled auto-merge (squash) December 24, 2023 15:50
@charliermarsh charliermarsh merged commit 5bce699 into main Dec 24, 2023
3 checks passed
@charliermarsh charliermarsh deleted the charlie/html branch December 24, 2023 16:04
@zanieb
Copy link
Member

zanieb commented Dec 24, 2023

Why the rush? :p

@charliermarsh
Copy link
Member Author

I didn’t assume anyone would be reviewing anything for the next week and I don’t want PRs to sit, so erring on the side of merging. If anyone wants to review they are welcome and I will fix in follow-up commits.

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

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

nice work!

#[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

Utf8(#[from] std::str::Utf8Error),

#[error(transparent)]
UrlParse(#[from] url::ParseError),
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 also show the input string, url::ParseError is a value-less enum


/// Parse the list of [`File`]s from the simple HTML page returned by the given URL.
pub(crate) fn parse_simple(text: &str, base: &Url) -> Result<Vec<File>, Error> {
let dom = tl::parse(text, tl::ParserOptions::default()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

This needs an unwrap-safety comment

Comment on lines +121 to +126
// Extract the hash, which should be in the fragment.
let hashes = url
.fragment()
.map(|fragment| parse_hash(fragment, &url))
.transpose()?
.ok_or_else(|| Error::MissingHash(url.clone()))?;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can make hashes mandatory, in PEP 503 hashes are a SHOULD.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, but they’re currently required everywhere else.

/// Return the `Accept` header value for all supported media types.
#[inline]
const fn accepts() -> &'static str {
"application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html;q=0.2, text/html"
Copy link
Member

Choose a reason for hiding this comment

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

i'd q=0.2 the text/html too

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in the relative URLs PR but I’ll carve it out into a separate change if that doesn’t merge soon.

@charliermarsh
Copy link
Member Author

Thanks for the nice review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the html PEP 503 simple repository api
3 participants