Skip to content

Add compatibility for Pyodide-tagged wheels #804

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

Open
wants to merge 6 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
9 changes: 9 additions & 0 deletions src/packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:
yield f"linux_{arch}"


def _emscripten_platforms() -> Iterator[str]:
pyodide_abi_version = sysconfig.get_config_var("PYODIDE_ABI_VERSION")
if pyodide_abi_version:
yield f"pyodide_{pyodide_abi_version}_wasm32"
yield from _generic_platforms()
Comment on lines +554 to +556
Copy link
Member

@jezdez jezdez May 26, 2025

Choose a reason for hiding this comment

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

Should this really yield the generic platform here as well, or is an else missing, so that _generic_platforms is yielded similar to the fallback in platform_tags?

Suggested change
if pyodide_abi_version:
yield f"pyodide_{pyodide_abi_version}_wasm32"
yield from _generic_platforms()
if pyodide_abi_version:
yield f"pyodide_{pyodide_abi_version}_wasm32"
else:
yield from _generic_platforms()

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is correct as is, since you want to also be able to match emscripten_... tags. pyodide is just a more specific tag.

Copy link

@agriyakhetarpal agriyakhetarpal May 27, 2025

Choose a reason for hiding this comment

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

If I've understood @hoodmane's recent work correctly, all our forthcoming tags will be labelled with pyodide_YYYY_N as per the Pyodide ABI information at https://pyodide.org/en/stable/development/abi.html#pyodide-2025-0-under-development and with PEP 783: https://peps.python.org/pep-0783/#specification that packaging will implement through this PR. I think the distinction is important, as emscripten is no longer the same as pyodide since 2025_0. In 2024, one could have both 2024_0 and emscripten_3_1_58, which meant the same thing. 2025_0 does not have an emcripten_4_0_9 equivalent.

Copy link
Author

Choose a reason for hiding this comment

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

I think we should keep it as is because emscripten_4_0_9 is the name of the platform and so it's the default tag. If anyone has wheels with this platform it makes sense to accept them.

Choose a reason for hiding this comment

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

Yes, okay to keep it if you say so! :)



def _generic_platforms() -> Iterator[str]:
yield _normalize_string(sysconfig.get_platform())

Expand All @@ -563,6 +570,8 @@ def platform_tags() -> Iterator[str]:
return ios_platforms()
elif platform.system() == "Linux":
return _linux_platforms()
elif platform.system() == "Emscripten":
return _emscripten_platforms()
else:
return _generic_platforms()

Expand Down
38 changes: 38 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,44 @@ def test_cpython_first_none_any_tag(self, monkeypatch):
interpreter = f"cp{tags.interpreter_version()}"
assert tag == tags.Tag(interpreter, "none", "any")

def test_emscripten(self, mock_interpreter_name, monkeypatch):
expected_interpreter = "cp" + tags._version_nodot(sys.version_info[:2])
if mock_interpreter_name("CPython"):
monkeypatch.setattr(
tags, "_cpython_abis", lambda _1, _2: [expected_interpreter]
)
monkeypatch.setattr(platform, "system", lambda: "Emscripten")
monkeypatch.setattr(
sysconfig, "get_platform", lambda: "emscripten-3.1.58-wasm32"
)
assert list(tags.platform_tags()) == ["emscripten_3_1_58_wasm32"]
result = list(tags.sys_tags())
assert result[0] == tags.Tag(
expected_interpreter, expected_interpreter, "emscripten_3_1_58_wasm32"
)

def test_pyodide(self, mock_interpreter_name, monkeypatch):
expected_interpreter = "cp" + tags._version_nodot(sys.version_info[:2])
monkeypatch.setitem(
sysconfig.get_config_vars(), "PYODIDE_ABI_VERSION", "2024_0"
)
if mock_interpreter_name("CPython"):
monkeypatch.setattr(
tags, "_cpython_abis", lambda _1, _2: [expected_interpreter]
)
monkeypatch.setattr(platform, "system", lambda: "Emscripten")
monkeypatch.setattr(
sysconfig, "get_platform", lambda: "emscripten-3.1.58-wasm32"
)
assert list(tags.platform_tags()) == [
"pyodide_2024_0_wasm32",
"emscripten_3_1_58_wasm32",
]
result = list(tags.sys_tags())
assert result[0] == tags.Tag(
expected_interpreter, expected_interpreter, "pyodide_2024_0_wasm32"
)


class TestBitness:
def teardown_method(self):
Expand Down