Skip to content

Commit faf2a4e

Browse files
authored
chore: Add powershell path check for code executor (#6212)
1 parent b1ae4ac commit faf2a4e

File tree

1 file changed

+8
-1
lines changed
  • python/packages/autogen-ext/src/autogen_ext/code_executors

1 file changed

+8
-1
lines changed

python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import re
3+
import shutil
34
from dataclasses import dataclass
45
from pathlib import Path
56
from textwrap import dedent, indent
@@ -159,7 +160,13 @@ def lang_to_cmd(lang: str) -> str:
159160
if lang in ["shell"]:
160161
return "sh"
161162
if lang in ["pwsh", "powershell", "ps1"]:
162-
return "pwsh"
163+
# Check if pwsh is available, otherwise fall back to powershell
164+
if shutil.which("pwsh") is not None:
165+
return "pwsh"
166+
elif shutil.which("powershell") is not None:
167+
return "powershell"
168+
else:
169+
raise ValueError(f"Powershell or pwsh is not installed. Please install one of them.")
163170
else:
164171
raise ValueError(f"Unsupported language: {lang}")
165172

0 commit comments

Comments
 (0)