Skip to content

Commit

Permalink
Try copying Windows executable
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Feb 3, 2025
1 parent 2e4dd4a commit d2427b9
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions conda_lock/conda_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pathlib
import shlex
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -619,21 +620,32 @@ def make_fake_python_binary(prefix: str) -> None:
print(stderr_message, file=sys.stderr, flush=True, end='')
if "-m pip" not in cmd:
if "-m pip" in cmd:
# Simulate an empty `pip inspect` output
print('{}', flush=True)
else:
raise RuntimeError("Expected to invoke pip module with `-m pip`.")
"""
)
)

if sys.platform == "win32":
# On Windows, create a batch file that calls the script
fake_python_binary = pathlib.Path(prefix) / "Scripts" / "python.bat"
# On Windows, copy sys.executable to prefix/Scripts/python.exe
fake_python_binary = pathlib.Path(prefix) / "Scripts" / "python.exe"
fake_python_binary.parent.mkdir(parents=True, exist_ok=True)
batch_content = dedent(f"""\

# Copy the existing python.exe into the fake environment
shutil.copyfile(sys.executable, fake_python_binary)

# Adjust the environment to ensure our fake script is executed
# Create a wrapper batch file that sets PYTHONPATH
wrapper_batch = pathlib.Path(prefix) / "Scripts" / "python.bat"
wrapper_batch_content = dedent(f"""\
@echo off
"{sys.executable}" "{fake_python_script}" %*
set PYTHONPATH={prefix};%PYTHONPATH%
"{fake_python_binary}" %*
""")
fake_python_binary.write_text(batch_content)
wrapper_batch.write_text(wrapper_batch_content)
else:
# On Unix-like systems, create a shell script that calls the script
fake_python_binary = pathlib.Path(prefix) / "bin" / "python"
Expand Down

0 comments on commit d2427b9

Please sign in to comment.