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

Fix python path #277

Merged
merged 3 commits into from
Jun 4, 2024
Merged
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
41 changes: 25 additions & 16 deletions codex/common/exec_external_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,29 @@ async def execute_command(
# Set the python path by replacing the env 'PATH' with the provided python path
venv = os.environ.copy()
if python_path:
# PATH prioritize first occurrence of python_path, so we need to prepend.
# Ensure python_path is a string
python_path = str(python_path)
venv["PATH"] = f"{python_path}:{venv['PATH']}"
r = await asyncio.create_subprocess_exec(
*command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=str(cwd),
env=venv,
)
stdout, stderr = await r.communicate()
if r.returncode == 0:
return (stdout or stderr).decode("utf-8")

if raise_on_error:
raise ValidationError((stderr or stdout).decode("utf-8"))
else:
return (stderr or stdout).decode("utf-8")

try:
r = await asyncio.create_subprocess_exec(
*command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=str(cwd),
env=venv,
)
stdout, stderr = await r.communicate()
stdout, stderr = stdout.decode("utf-8"), stderr.decode("utf-8")

if r.returncode == 0:
return stdout or stderr

logger.error(f"Command failed with stderr: {stderr}")
if raise_on_error:
raise ValidationError(stderr or stdout)
else:
return stderr or stdout
except Exception as e:
logger.error(f"Exception during command execution: {e}")
raise
Loading