|
3 | 3 | import os
|
4 | 4 | import shutil
|
5 | 5 | import sys
|
| 6 | +import textwrap |
6 | 7 | import tomllib
|
7 | 8 | import typing
|
8 | 9 | from collections.abc import Set
|
@@ -476,6 +477,32 @@ def build(options: Options, tmp_path: Path) -> None:
|
476 | 477 |
|
477 | 478 | call("pyodide", "venv", venv_dir, env=virtualenv_create_env)
|
478 | 479 |
|
| 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 | + |
479 | 506 | virtualenv_env["PATH"] = os.pathsep.join(
|
480 | 507 | [
|
481 | 508 | str(venv_dir / "bin"),
|
|
0 commit comments