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

adds better windows shell support #5053

Merged

Conversation

bmarroquin
Copy link
Contributor

@bmarroquin bmarroquin commented Jan 17, 2022

Pull Request Check List

This change resolves a lot duplicated issues.
Resolves: #5050, Resolves #4996, Resolves #4993, Resolves #4560, Resolves #2793, Resolves #2156, Resolves #1642

  • Added tests for changed code.
  • Updated documentation for changed code.

There are not tests for activating shells and this doesn't require a change in documentation. This lines up Windows behavior with the documentation.

@finswimmer finswimmer requested a review from a team January 17, 2022 20:17
src/poetry/utils/shell.py Outdated Show resolved Hide resolved
if WINDOWS:
return env.execute(self.path)
if self._name == "powershell":
args = ["-NoExit", "-File", str(activate_path)]

Choose a reason for hiding this comment

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

Subjective opinion: I like launching with -nologo to not have to see

PowerShell 7.2.1
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

each time.

Copy link
Member

Choose a reason for hiding this comment

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

Given that it is cosmetic, I'd rather not add more arguments past the bare minimum, personally.

Choose a reason for hiding this comment

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

Understood. It is definitely subjective on my part -- I like the "clean sheet" in front of me after typing poetry shell, but typing cls isn't a big deal.

@jrobbins-LiveData
Copy link

In my "wish list" for a nicer Windows cmd.exe experience in Poetry, there are only two items you didn't cover in your excellent PR.

  1. command history (up/down arrow traversal of typed commands) in a Windows Terminal cmd.exe launched by poetry shell. This thread discusses the problem and offers a solution I have tested with poetry. If you added the following to Shell's __init__ method, using the implementation given in that thread for set_console_history_info(), you'd ensure that console command history will work in the Poetry shell. Without this, poetry shell inside Windows Terminal cmd.exe is markedly less usable.
        if WINDOWS:
            set_console_history_info()
  1. this one is a more subjective "nice to have" feature: while executing the relevant activate script, it is nice to set the title of the console to the name of the folder. In the case of cmd.exe, this is simply adding via && another command to the args, e.g. "title", env.path.name. In the case of powershell/pwsh, it the added command includes '& {$host.UI.RawUI.WindowTitle = "%s"}' % env.path.name

@neersighted
Copy link
Member

I'm a little leery of doing too much -- poetry shell is intentionally very minimal. This is a lesson learned from the pain and breakage that came from Pipenv's customized and curated, but ultimately brittle shell experience.

That being said, I'd still consider the suggestions made by @jrobbins-LiveData if they are added to this PR and don't look to be a big maintenance burden, since they seem to be minor and relatively stable.

@jrobbins-LiveData
Copy link

I agree, @neersighted, regarding the minimalist approach. Of all my feedback, I think I'd prioritize pwsh.exe support.

As to command history support, technically perhaps that's more properly a Windows Terminal concern. The reason I bring it up here is that if one "manually" simply runs Scripts\activate.bat in one's existing shell, one gets activation without losing command history because it is still the same shell. poetry shell, by necessity, launches a new shell, and so hits a Windows Terminal default limit, which is fixed by set_console_history_info().

In a regular command prompt window (not Windows Terminal), one can address this problem in its Properties page in the spot I've circled
image

@jrobbins-LiveData
Copy link

@neersighted , perhaps there could be an optional "user script" hook (configured via poetry's config mechanism?) , that the internal process.run would call inline if configured? This would allow for setting the title, configuring the command history buffer, etc, if the user wanted to configure the logic, without overly burdening the poetry code with taking on too much?

uses subprocess.run()
adds support for pwsh
@bmarroquin
Copy link
Contributor Author

bmarroquin commented Jan 19, 2022

@neersighted updated the PR. Only handled the changes that keep everything minimal.
There is a side effect that pwsh might work for non-windows environments. PR #5047 was trying to enable that. I did not test the change on non-windows environments.

@jrobbins-LiveData Thanks for all the feedback, appreciate it. I know this doesn't cover your wish list, but there are some minor upgrades 😊.

src/poetry/utils/shell.py Outdated Show resolved Hide resolved
@neersighted neersighted merged commit 28d05d0 into python-poetry:master Jan 22, 2022
@kkthxbye kkthxbye mentioned this pull request Jan 22, 2022
@finswimmer finswimmer mentioned this pull request Mar 6, 2022
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.