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 compatibility for Pyodide-tagged wheels #804

Open
wants to merge 4 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 @@ -502,6 +502,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()


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

Expand All @@ -514,6 +521,8 @@ def platform_tags() -> Iterator[str]:
return mac_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 @@ -1364,6 +1364,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, "cp312", "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, "cp312", "pyodide_2024_0_wasm32"
)


class TestBitness:
def teardown_method(self):
Expand Down
Loading