Skip to content

Commit

Permalink
Add implied assertion in WheelInfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Carreau committed Oct 21, 2024
1 parent 4044983 commit ab71634
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions micropip/wheelinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def add_pkg_version(
releases[version] = [
{
"filename": filename,
"url": filename,
"url": f"http://fake.domain/f/{filename}",
"digests": {
"sha256": Wildcard(),
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab71634

Please sign in to comment.