Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions micropip/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def check_compatible(filename: str) -> None:
try:
tags = parse_tags(filename)
except InvalidWheelFilename:
raise ValueError(f"Wheel filename is invalid: {filename}") from None
raise ValueError(f"Wheel filename is invalid: {filename!r}") from None
except InvalidVersion:
raise ValueError(f"Wheel version is invalid: {filename}") from None
raise ValueError(f"Wheel version is invalid: {filename!r}") from None

tag: Tag = next(iter(tags))
if "emscripten" not in tag.platform:
Expand Down
5 changes: 5 additions & 0 deletions micropip/wheelinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class WheelInfo:
_dist_info: Path | None = None

def __post_init__(self):
assert (
self.url.startwith(p) for p in ("http:", "https:", "emfs:", "file:")
), self.url
self._project_name = safe_name(self.name)

@classmethod
Expand All @@ -63,6 +66,8 @@ def from_url(cls, url: str) -> "WheelInfo":
See https://www.python.org/dev/peps/pep-0427/#file-name-convention
"""
parsed_url = urlparse(url)
if parsed_url.scheme == "":
url = "file:///" + url
file_name = Path(parsed_url.path).name
name, version, build, tags = parse_wheel_filename(file_name)
return WheelInfo(
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")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not entirely clear if the typo here was on purpose.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty accidental to me. If it were on purpose you would expect a comment.

await micropip.install("https://x.com/xxx-1.0.0-py3-none-any.whl")


@pytest.mark.skip_refcount_check
Expand Down
12 changes: 9 additions & 3 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
"path",
[
SNOWBALL_WHEEL,
f"/{SNOWBALL_WHEEL}" f"a/{SNOWBALL_WHEEL}",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a mistake, and a , is needed.

f"/{SNOWBALL_WHEEL}",
f"a/{SNOWBALL_WHEEL}",
f"/a/{SNOWBALL_WHEEL}",
f"//a/{SNOWBALL_WHEEL}",
],
)
@pytest.mark.parametrize("protocol", ["https:", "file:", "emfs:", ""])
@pytest.mark.parametrize(
"protocol",
["http:", "https:", "file:", "emfs:", ""],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no clue what emfs is..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stands for "Emscripten file system". It's needed because file: points to files in the actual file system. Probably could use some comments and better documentation.

)
def test_parse_wheel_url1(protocol, path):
pytest.importorskip("packaging")
from micropip.transaction import WheelInfo

url = protocol + path
wheel = WheelInfo.from_url(url)

check_url = url if protocol else "file:///" + path
assert wheel.name == "snowballstemmer"
assert str(wheel.version) == "2.0.0"
assert wheel.sha256 is None
assert wheel.filename == SNOWBALL_WHEEL
assert wheel.url == url
assert wheel.url == check_url
assert wheel.tags == frozenset(
{Tag("py2", "none", "any"), Tag("py3", "none", "any")}
)
Expand Down