From ab7163431125b3972b3a4ce1f57e2cbeb9a37bd4 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Mon, 21 Oct 2024 14:47:08 +0200 Subject: [PATCH] Add implied assertion in WheelInfo Some simple indexes (anaconda), only list the full-pathname of download URL (assuming same domain, which make sens). WheelInfo.download does not work on this case at it tries to make the requests on the current page domain. Thus we implicitely assume that URL start with http (well https:// would be better, but when you prototype local index could be http.) The error can be weird if we let it propagate (bad ziplife as you try to decode often a 404 html page as ZIP). This thus just add an assert at construction time to catch the error early. It should in the end be pushed earler in the code (likely at parsing time), where we are likely to know the index URL and be able to resolve URLs at that time. --- micropip/wheelinfo.py | 1 + tests/conftest.py | 2 +- tests/test_install.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/micropip/wheelinfo.py b/micropip/wheelinfo.py index c6d255f..8c77cbf 100644 --- a/micropip/wheelinfo.py +++ b/micropip/wheelinfo.py @@ -54,6 +54,7 @@ class WheelInfo: _dist_info: Path | None = None def __post_init__(self): + assert self.url.startswith("http"), self.url self._project_name = safe_name(self.name) @classmethod diff --git a/tests/conftest.py b/tests/conftest.py index af55b88..c704a57 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -270,7 +270,7 @@ def add_pkg_version( releases[version] = [ { "filename": filename, - "url": filename, + "url": f"http://fake.domain/f/{filename}", "digests": { "sha256": Wildcard(), }, diff --git a/tests/test_install.py b/tests/test_install.py index 111926a..aa89b0e 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -257,7 +257,7 @@ def _mock_fetch_bytes(arg, *args, **kwargs): msg = "Access-Control-Allow-Origin" with pytest.raises(ValueError, match=msg): - await micropip.install("htps://x.com/xxx-1.0.0-py3-none-any.whl") + await micropip.install("https://x.com/xxx-1.0.0-py3-none-any.whl") @pytest.mark.skip_refcount_check