π OpenHands: AI-Driven Development
Bugfix: make extraction of poetry_venvs_path more robust (#7920)
Michael Panchenko76cad626eda8
diff --git a/openhands/runtime/impl/local/local_runtime.py b/openhands/runtime/impl/local/local_runtime.pyindex 05eafaec8e..02aa2de9c0 100644--- a/openhands/runtime/impl/local/local_runtime.py+++ b/openhands/runtime/impl/local/local_runtime.py@@ -207,19 +207,31 @@ class LocalRuntime(ActionExecutionClient):env['PYTHONPATH'] = f'{code_repo_path}:$PYTHONPATH'env['OPENHANDS_REPO_PATH'] = code_repo_pathenv['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_pathlogger.debug(f'POETRY_VIRTUALENVS_PATH: {poetry_venvs_path}')