Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implied assertion in WheelInfo #145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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
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
10 changes: 7 additions & 3 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
"path",
[
SNOWBALL_WHEEL,
f"/{SNOWBALL_WHEEL}" f"a/{SNOWBALL_WHEEL}",
Copy link
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
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
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
url = protocol + path if protocol else "file:///" + path
Copy link
Member

Choose a reason for hiding this comment

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

Why not put file:/// in the parametrize decorator and do:

Suggested change
url = protocol + path if protocol else "file:///" + path
url = protocol + path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's me I'm dumb I need to put that lower; I want to check that WheelInfo.from_url(url) parses things that have no protocol as local files.

wheel = WheelInfo.from_url(url)
assert wheel.name == "snowballstemmer"
assert str(wheel.version) == "2.0.0"
Expand Down
Loading