From af2945321aef9730ba96f27251df36fd28dcbcdf Mon Sep 17 00:00:00 2001 From: Artem Samokhin Date: Mon, 20 Jan 2025 14:06:07 +1300 Subject: [PATCH 1/4] Add support for extra variants of relative urls for simple html pypi API --- micropip/package_index.py | 8 +++++--- .../fake-pkg-micropip-test_simple.html | 17 +++++++++++++++++ tests/test_package_index.py | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html diff --git a/micropip/package_index.py b/micropip/package_index.py index 49974b7b..79930fab 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 urlparse, urlunparse, urljoin 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/fake-pkg-micropip-test_simple.html b/tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html new file mode 100644 index 00000000..bfca838a --- /dev/null +++ b/tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html @@ -0,0 +1,17 @@ + + + + + Links for fake-pkg-micropip-test + + +

Links for fake-pkg-micropip-test

+fake_pkg_micropip_test-1.0.0.tar.gz +fake_pkg_micropip_test-1.0.0-py3-none-any.whl +fake_pkg_micropip_test-1.1.0.tar.gz +fake_pkg_micropip_test-1.1.0-py3-none-any.whl +fake_pkg_micropip_test-1.2.0-py3-none-any.whl +fake_pkg_micropip_test-1.3.0-py3-none-any.whl +fake_pkg_micropip_test-1.4.0-py3-none-any.whl + + diff --git a/tests/test_package_index.py b/tests/test_package_index.py index 9bba3d07..e5c90644 100644 --- a/tests/test_package_index.py +++ b/tests/test_package_index.py @@ -43,7 +43,7 @@ def test_project_info_from_simple_json(name): @pytest.mark.parametrize( - "name", ["numpy", "black", "pytest", "snowballstemmer", "pytz"] + "name", ["numpy", "black", "pytest", "snowballstemmer", "pytz", "fake-pkg-micropip-test"] ) def test_project_info_from_simple_html(name): test_file = TEST_PYPI_RESPONSE_DIR / f"{name}_simple.html" From 084667770561d4ea0e8aaa06a913beb7ad7ccf49 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 02:14:35 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- micropip/package_index.py | 2 +- tests/test_package_index.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/micropip/package_index.py b/micropip/package_index.py index 79930fab..562a2521 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, urljoin +from urllib.parse import urljoin, urlparse, urlunparse from packaging.utils import InvalidWheelFilename from packaging.version import InvalidVersion, Version diff --git a/tests/test_package_index.py b/tests/test_package_index.py index e5c90644..2ba8582a 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", "fake-pkg-micropip-test"] + "name", + ["numpy", "black", "pytest", "snowballstemmer", "pytz", "fake-pkg-micropip-test"], ) def test_project_info_from_simple_html(name): test_file = TEST_PYPI_RESPONSE_DIR / f"{name}_simple.html" From ca062ec507efd7684fb635d87b4e08175c2a40b3 Mon Sep 17 00:00:00 2001 From: Artem Samokhin Date: Tue, 21 Jan 2025 09:36:02 +1300 Subject: [PATCH 3/4] changelog & code review --- CHANGELOG.md | 6 ++++++ .../fake-pkg-micropip-test_simple.html | 17 ----------------- .../relative-urls-test_simple.html | 17 +++++++++++++++++ tests/test_package_index.py | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) delete mode 100644 tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html create mode 100644 tests/test_data/pypi_response/relative-urls-test_simple.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 86403b05..522e4d83 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/tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html b/tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html deleted file mode 100644 index bfca838a..00000000 --- a/tests/test_data/pypi_response/fake-pkg-micropip-test_simple.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Links for fake-pkg-micropip-test - - -

Links for fake-pkg-micropip-test

-fake_pkg_micropip_test-1.0.0.tar.gz -fake_pkg_micropip_test-1.0.0-py3-none-any.whl -fake_pkg_micropip_test-1.1.0.tar.gz -fake_pkg_micropip_test-1.1.0-py3-none-any.whl -fake_pkg_micropip_test-1.2.0-py3-none-any.whl -fake_pkg_micropip_test-1.3.0-py3-none-any.whl -fake_pkg_micropip_test-1.4.0-py3-none-any.whl - - 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 00000000..7f5e83d5 --- /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 2ba8582a..e57dae40 100644 --- a/tests/test_package_index.py +++ b/tests/test_package_index.py @@ -44,7 +44,7 @@ def test_project_info_from_simple_json(name): @pytest.mark.parametrize( "name", - ["numpy", "black", "pytest", "snowballstemmer", "pytz", "fake-pkg-micropip-test"], + ["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" From df8dfc6ac84bd019a04b578d6c83e875a13691aa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:37:13 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 522e4d83..81404672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix a bug that prevented non-standard relative urls to be treated as such +- 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)