Skip to content

Commit

Permalink
Fix python path (#277)
Browse files Browse the repository at this point in the history
* Fix python path

* formatting
  • Loading branch information
aarushik93 authored Jun 4, 2024
1 parent d93565d commit 6e38b03
Showing 1 changed file with 25 additions and 16 deletions.
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

0 comments on commit 6e38b03

Please sign in to comment.