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

Updated code_utils.py & local_commandline_code_executor.py (powershell to pwsh) #1710

Merged
merged 18 commits into from
Feb 19, 2024
Merged

Updated code_utils.py & local_commandline_code_executor.py (powershell to pwsh) #1710

merged 18 commits into from
Feb 19, 2024

Conversation

abhaymathur21
Copy link
Contributor

@abhaymathur21 abhaymathur21 commented Feb 17, 2024

Updated the 'powershell' command to 'pwsh' for a ps1 executable file

Why are these changes needed?

I was trying to use autogen to execute terminal commands (eg: git status, ls) but it was throwing an error. So these changes are required if terminal commands are to be executed in the new 7.x version of PowerShell. To execute terminal commands in powershell, autogen first makes a ps1 shell script with those commands written in it and then executes that ps1 shell script. In order for that shell script execution to work, these changes are required.

In March 2020, microsoft released a new version of powershell (7.0) in which the powershell.exe file was renamed to pwsh.exe
image
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.4

In your code, if the user is working in a powershell window and a '.ps1' script is to be executed, your code uses the 'powershell' command to execute it which has now been replaced with 'pwsh' in the new Microsoft PowerShell version 7.0
image
image

So in your code I replaced the command 'powershell' with 'pwsh' when a ps1 script has to be executed

I also added the 'pwsh' command to the list of commands in the local_commandline_code_executor.py file
image

Checks

Updated the powershell command to pwsh
@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (c7d9fef) 39.21% compared to head (247d6c2) 50.59%.

Files Patch % Lines
autogen/code_utils.py 76.47% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1710       +/-   ##
===========================================
+ Coverage   39.21%   50.59%   +11.37%     
===========================================
  Files          57       57               
  Lines        6082     6096       +14     
  Branches     1363     1484      +121     
===========================================
+ Hits         2385     3084      +699     
+ Misses       3502     2766      -736     
- Partials      195      246       +51     
Flag Coverage Δ
unittests 50.50% <77.77%> (+11.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Have you also checked out the new code executor? It’s here https://github.com/microsoft/autogen/blob/main/autogen/coding/local_commandline_code_executor.py

You can use the new code executor like

proxy = CoversableAgent(“proxy”, code_execution_config={“executor”: “commadline-local”})

Perhaps you want to add the handling for powershell there as well? It’s okay to do it in a separate PR.

autogen/code_utils.py Outdated Show resolved Hide resolved
autogen/code_utils.py Outdated Show resolved Hide resolved
@sonichi sonichi enabled auto-merge February 19, 2024 17:31
@sonichi sonichi added this pull request to the merge queue Feb 19, 2024
Merged via the queue into microsoft:main with commit 2750391 Feb 19, 2024
46 of 57 checks passed
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
…l to pwsh) (microsoft#1710)

* Update code_utils.py

Updated the powershell command to pwsh

* Update code_utils.py

added a split to handle powershell in the first condition as well

* Update local_commandline_code_executor.py

added "pwsh" as a command option in lang variable

* Update autogen/coding/local_commandline_code_executor.py

Co-authored-by: Eric Zhu <[email protected]>

* Update code_utils.py

* Update code_utils.py

fixed formatting

* Update code_utils.py

defined a function to detect whether 'powershell' or 'pwsh' works and accordingly use the one that works

* Update code_utils.py

fixed formatting

* Update and rename test_code.py to test_code_utils.py

added a unit test for get_powershell_command function in code_utils.py

* Update test_code_utils.py

fixed formatting

* Update test_code_utils.py

fixed formatting

* Update autogen/code_utils.py

Co-authored-by: Chi Wang <[email protected]>

---------

Co-authored-by: Eric Zhu <[email protected]>
Co-authored-by: Chi Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants