Skip to content

Commit 78b3f00

Browse files
committed
Make create_pip_script work with uv actually this time [integration]
Weird hack to work around: astral-sh/python-build-standalone#380 If we resolve the symlink all the way, the python-host interpreter works but won't install into our pyodide venv. If we don't resolve the symlink, sys.prefix is calculated incorrectly. To ensure that we get the right sys.prefix, we explicitly set it with the PYTHONHOME environment variable and then call the symlink.
1 parent a4b038c commit 78b3f00

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pyodide_build/out_of_tree/venv.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,37 @@ def create_pip_script(venv_bin):
223223
# pyodide venv.
224224
host_python_path = venv_bin / f"python{get_pyversion()}-host"
225225
pip_path = venv_bin / "pip_patched"
226+
python_host_link = venv_bin / "python-host-link"
226227

227228
# To support the "--clear" and "--no-clear" args, we need to remove
228229
# the existing symlinks before creating new ones.
229230
host_python_path.unlink(missing_ok=True)
230-
(venv_bin / "python-host").unlink(missing_ok=True)
231+
python_host_link.unlink(missing_ok=True)
231232
for pip in venv_bin.glob("pip*"):
232233
if pip == pip_path:
233234
continue
234235
pip.unlink(missing_ok=True)
235236
pip.symlink_to(pip_path)
236237

237-
host_python_path.symlink_to(sys.executable)
238-
# in case someone needs a Python-version-agnostic way to refer to python-host
239-
(venv_bin / "python-host").symlink_to(sys.executable)
238+
# Weird hack to work around:
239+
# https://github.com/astral-sh/python-build-standalone/issues/380
240+
# If we resolve the symlink all the way, the python-host interpreter works
241+
# but won't install into our pyodide venv. If we don't resolve the symlink,
242+
# sys.prefix is calculated incorrectly. To ensure that we get the right
243+
# sys.prefix, we explicitly set it with the PYTHONHOME environment variable
244+
# and then call the symlink.
245+
python_host_link.symlink_to(sys.executable)
246+
pythonhome = Path(sys._base_executable).parents[1]
247+
host_python_path.write_text(
248+
dedent(
249+
f"""\
250+
#!/bin/sh
251+
exec env PYTHONHOME={pythonhome} {sys.executable} $@
252+
"""
253+
)
254+
)
255+
host_python_path.chmod(0o777)
256+
(venv_bin / "python-host").symlink_to(host_python_path)
240257

241258
pip_path.write_text(
242259
# Other than the shebang and the monkey patch, this is exactly what

0 commit comments

Comments
 (0)