Skip to content

Commit b3ee8d1

Browse files
committed
Add workaround for pyodide/pyodide-build#143
1 parent 62b57e6 commit b3ee8d1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cibuildwheel/platforms/pyodide.py

+27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import shutil
55
import sys
6+
import textwrap
67
import tomllib
78
import typing
89
from collections.abc import Set
@@ -476,6 +477,32 @@ def build(options: Options, tmp_path: Path) -> None:
476477

477478
call("pyodide", "venv", venv_dir, env=virtualenv_create_env)
478479

480+
# WORKAROUND (should be upstreamed into pyodide)
481+
base_python = (identifier_tmp_dir / "build" / "venv" / "bin" / "python").resolve()
482+
(venv_dir / "bin" / "python-host-link").symlink_to(base_python)
483+
(venv_dir / "bin" / "python-host").unlink()
484+
(venv_dir / "bin" / "python-host").write_text(
485+
textwrap.dedent(f"""
486+
#!/bin/bash
487+
export PYTHONHOME={base_python.parent.parent}
488+
exec {venv_dir / "bin" / "python-host-link"} -s "$@"
489+
""")
490+
)
491+
(venv_dir / "bin" / "python-host").chmod(0o755)
492+
493+
# make the python3.12-host bin point to the python-host script
494+
(venv_dir / "bin" / "python3.12-host").unlink()
495+
(venv_dir / "bin" / "python3.12-host").symlink_to(venv_dir / "bin" / "python-host")
496+
497+
# make the first line of the pip executable point to the
498+
# python-host script the `/usr/bin/env` bit is needed to use a
499+
# script as a shebang interpreter, at least on macOS
500+
pip_executable = venv_dir / "bin" / "pip"
501+
pip_executable_content = pip_executable.read_text().splitlines()
502+
pip_executable_content[0] = f"#!/usr/bin/env {venv_dir / 'bin' / 'python-host'}"
503+
pip_executable.write_text("\n".join(pip_executable_content))
504+
# END WORKAROUND
505+
479506
virtualenv_env["PATH"] = os.pathsep.join(
480507
[
481508
str(venv_dir / "bin"),

0 commit comments

Comments
 (0)