Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code_utils.py powershell command bugfix in MacOS #1963

Merged
merged 21 commits into from
Mar 18, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,29 @@ def get_powershell_command():
return "pwsh"

except (FileNotFoundError, NotADirectoryError):
if WIN32:
logging.warning("Neither powershell nor pwsh is installed but it is a Windows OS")
return None
if WIN32 and FileNotFoundError:
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
logging.warning("Neither powershell.exe nor pwsh.exe is present but it is a Windows OS")

elif WIN32 and NotADirectoryError:
logging.warning(
"PowerShell is either not installed or its path is not given properly in the environment variable PATH. Please check the path and try again."
)

return None

powershell_command = get_powershell_command()
except PermissionError:
logging.warning("The application has no permission to run powershell")
return None


def _cmd(lang):
if lang.startswith("python") or lang in ["bash", "sh", powershell_command]:
if lang.startswith("python") or lang in ["bash", "sh"]:
return lang
if lang in ["shell"]:
return "sh"
if lang in ["ps1", "pwsh", "powershell"]:
return powershell_command
powershell_command = get_powershell_command()
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
return powershell_command if powershell_command is not None else "sh"

raise NotImplementedError(f"{lang} not recognized in code execution")

Expand Down
Loading