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 extra variants of relative urls for simple html pypi API #174

Merged
merged 4 commits into from
Jan 21, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- Fix a bug that prevented non-standard relative urls to be treated as such
(the ones that starts with `../` or `./`)
[#174](https://github.com/pyodide/micropip/pull/174)

## [0.8.0] - 2024/12/15

### Added
Expand Down
8 changes: 5 additions & 3 deletions micropip/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dataclasses import dataclass
from functools import partial
from typing import Any
from urllib.parse import urlparse, urlunparse
from urllib.parse import urljoin, urlparse, urlunparse

from packaging.utils import InvalidWheelFilename
from packaging.version import InvalidVersion, Version
Expand Down Expand Up @@ -130,8 +130,10 @@ def _parse_pep691_response(
version = parse_version(filename)
except (InvalidVersion, InvalidWheelFilename):
continue
if file["url"].startswith("/"):
file["url"] = index_base_url + file["url"]

is_absolute_url = bool(urlparse(file["url"]).netloc)
if not is_absolute_url:
file["url"] = urljoin(index_base_url, file["url"])

releases[version].append(file)

Expand Down
17 changes: 17 additions & 0 deletions tests/test_data/pypi_response/relative-urls-test_simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta name="pypi:repository-version" content="1.1">
<title>Links for relative-url-test</title>
</head>
<body>
<h1>Links for relative-url-test</h1>
<a href="../../packages/relative-url-test/1.0.0/relative_url_test-1.0.0.tar.gz#sha256=aed8c5ebf0320f526d1550f1754afa69ebc20855224fc5a02a3d74fababd9fa4" data-requires-python="&gt;=3.6">relative_url_test-1.0.0.tar.gz</a>
<a href="../../packages/relative-url-test/1.0.0/relative_url_test-1.0.0-py3-none-any.whl#sha256=f4a7ba72e93bc97ff491b66d69063819ae2b75238bb653cd4c95e3f2847ce76e" data-requires-python="&gt;=3.6">relative_url_test-1.0.0-py3-none-any.whl</a>
<a href="../packages/relative-url-test/1.1.0/relative_url_test-1.1.0.tar.gz#sha256=bed8c5ebf0320f526d1550f1754afa69ebc20855224fc5a02a3d74fababd9fa5" data-requires-python="&gt;=3.6">relative_url_test-1.1.0.tar.gz</a>
<a href="../packages/relative-url-test/1.1.0/relative_url_test-1.1.0-py3-none-any.whl#sha256=c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a" data-requires-python="&gt;=3.6">relative_url_test-1.1.0-py3-none-any.whl</a>
<a href="./packages/relative-url-test/1.2.0/relative_url_test-1.2.0-py3-none-any.whl#sha256=d8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1b" data-requires-python="&gt;=3.6">relative_url_test-1.2.0-py3-none-any.whl</a>
<a href="/packages/relative-url-test/1.3.0/relative_url_test-1.3.0-py3-none-any.whl#sha256=e8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1c" data-requires-python="&gt;=3.6">relative_url_test-1.3.0-py3-none-any.whl</a>
<a href="packages/relative-url-test/1.4.0/relative_url_test-1.4.0-py3-none-any.whl#sha256=f8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1d" data-requires-python="&gt;=3.6">relative_url_test-1.4.0-py3-none-any.whl</a>
</body>
</html>
3 changes: 2 additions & 1 deletion tests/test_package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_project_info_from_simple_json(name):


@pytest.mark.parametrize(
"name", ["numpy", "black", "pytest", "snowballstemmer", "pytz"]
"name",
["numpy", "black", "pytest", "snowballstemmer", "pytz", "relative-urls-test"],
)
def test_project_info_from_simple_html(name):
test_file = TEST_PYPI_RESPONSE_DIR / f"{name}_simple.html"
Expand Down