From 43b72c405fae7b788d9080ab465ef20acd9bd8dc Mon Sep 17 00:00:00 2001 From: Leonardo Pinheiro Date: Sat, 5 Apr 2025 12:07:28 +1000 Subject: [PATCH] add pwsh path check --- .../src/autogen_ext/code_executors/_common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py b/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py index 4b1259ef04ee..b02654e4128a 100644 --- a/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py +++ b/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py @@ -1,5 +1,6 @@ import inspect import re +import shutil from dataclasses import dataclass from pathlib import Path from textwrap import dedent, indent @@ -159,7 +160,13 @@ def lang_to_cmd(lang: str) -> str: if lang in ["shell"]: return "sh" if lang in ["pwsh", "powershell", "ps1"]: - return "pwsh" + # Check if pwsh is available, otherwise fall back to powershell + if shutil.which("pwsh") is not None: + return "pwsh" + elif shutil.which("powershell") is not None: + return "powershell" + else: + raise ValueError(f"Powershell or pwsh is not installed. Please install one of them.") else: raise ValueError(f"Unsupported language: {lang}")