diff --git a/CHANGELOG.md b/CHANGELOG.md index 86403b0..8140467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/micropip/package_index.py b/micropip/package_index.py index 49974b7..562a252 100644 --- a/micropip/package_index.py +++ b/micropip/package_index.py @@ -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 @@ -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) diff --git a/tests/test_data/pypi_response/relative-urls-test_simple.html b/tests/test_data/pypi_response/relative-urls-test_simple.html new file mode 100644 index 0000000..7f5e83d --- /dev/null +++ b/tests/test_data/pypi_response/relative-urls-test_simple.html @@ -0,0 +1,17 @@ + + + + + Links for relative-url-test + + +

Links for relative-url-test

+relative_url_test-1.0.0.tar.gz +relative_url_test-1.0.0-py3-none-any.whl +relative_url_test-1.1.0.tar.gz +relative_url_test-1.1.0-py3-none-any.whl +relative_url_test-1.2.0-py3-none-any.whl +relative_url_test-1.3.0-py3-none-any.whl +relative_url_test-1.4.0-py3-none-any.whl + + diff --git a/tests/test_package_index.py b/tests/test_package_index.py index 9bba3d0..e57dae4 100644 --- a/tests/test_package_index.py +++ b/tests/test_package_index.py @@ -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"