Bugfix: make extraction of poetry_venvs_path more robust (#7920)

This commit is contained in:
Michael Panchenko 2025-04-18 19:33:52 +02:00 committed by GitHub
parent 7c23993344
commit 76cad626ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -207,19 +207,31 @@ class LocalRuntime(ActionExecutionClient):
env['PYTHONPATH'] = f'{code_repo_path}:$PYTHONPATH'
env['OPENHANDS_REPO_PATH'] = code_repo_path
env['LOCAL_RUNTIME_MODE'] = '1'
# Extract the poetry venv by parsing output of a shell command
# Equivalent to:
# run poetry show -v | head -n 1 | awk '{print $2}'
poetry_venvs_path = (
poetry_show_first_line = (
subprocess.check_output(
['poetry', 'show', '-v'],
env=env,
cwd=code_repo_path,
text=True,
# Redirect stderr to stdout
# Needed since there might be a message on stderr like
# "Skipping virtualenv creation, as specified in config file."
# which will cause the command to fail
stderr=subprocess.STDOUT,
shell=False,
)
.splitlines()[0]
.split(':')[1]
.strip()
)
if not poetry_show_first_line.lower().startswith('found:'):
raise RuntimeError(
"Cannot find poetry venv path. Please check your poetry installation."
f"First line of poetry show -v: {poetry_show_first_line}"
)
# Split off the 'Found:' part
poetry_venvs_path = poetry_show_first_line.split(':')[1].strip()
env['POETRY_VIRTUALENVS_PATH'] = poetry_venvs_path
logger.debug(f'POETRY_VIRTUALENVS_PATH: {poetry_venvs_path}')