Skip to content

Commit 5ce6e1f

Browse files
Add support for extra variants of relative urls for simple html pypi API (#174)
* Add support for extra variants of relative urls for simple html pypi API * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changelog & code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d74f7a5 commit 5ce6e1f

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
### Fixed
10+
11+
- Fix a bug that prevented non-standard relative urls to be treated as such
12+
(the ones that starts with `../` or `./`)
13+
[#174](https://github.com/pyodide/micropip/pull/174)
14+
915
## [0.8.0] - 2024/12/15
1016

1117
### Added

micropip/package_index.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dataclasses import dataclass
88
from functools import partial
99
from typing import Any
10-
from urllib.parse import urlparse, urlunparse
10+
from urllib.parse import urljoin, urlparse, urlunparse
1111

1212
from packaging.utils import InvalidWheelFilename
1313
from packaging.version import InvalidVersion, Version
@@ -130,8 +130,10 @@ def _parse_pep691_response(
130130
version = parse_version(filename)
131131
except (InvalidVersion, InvalidWheelFilename):
132132
continue
133-
if file["url"].startswith("/"):
134-
file["url"] = index_base_url + file["url"]
133+
134+
is_absolute_url = bool(urlparse(file["url"]).netloc)
135+
if not is_absolute_url:
136+
file["url"] = urljoin(index_base_url, file["url"])
135137

136138
releases[version].append(file)
137139

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="pypi:repository-version" content="1.1">
5+
<title>Links for relative-url-test</title>
6+
</head>
7+
<body>
8+
<h1>Links for relative-url-test</h1>
9+
<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>
10+
<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>
11+
<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>
12+
<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>
13+
<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>
14+
<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>
15+
<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>
16+
</body>
17+
</html>

tests/test_package_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def test_project_info_from_simple_json(name):
4343

4444

4545
@pytest.mark.parametrize(
46-
"name", ["numpy", "black", "pytest", "snowballstemmer", "pytz"]
46+
"name",
47+
["numpy", "black", "pytest", "snowballstemmer", "pytz", "relative-urls-test"],
4748
)
4849
def test_project_info_from_simple_html(name):
4950
test_file = TEST_PYPI_RESPONSE_DIR / f"{name}_simple.html"

0 commit comments

Comments
 (0)