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
Merged
Changes from all 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
21 changes: 17 additions & 4 deletions src/poetry/utils/shell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import signal
import subprocess
import sys

from pathlib import Path
Expand Down Expand Up @@ -67,8 +68,19 @@ def get(cls) -> "Shell":
return cls._shell

def activate(self, env: "VirtualEnv") -> Optional[int]:
activate_script = self._get_activate_script()
bin_dir = "Scripts" if WINDOWS else "bin"
activate_path = env.path / bin_dir / activate_script

if WINDOWS:
return env.execute(self.path)
if self._name in ("powershell", "pwsh"):
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.

else:
# /K will execute the bat file and
# keep the cmd process from terminating
args = ["/K", str(activate_path)]
completed_proc = subprocess.run([self.path, *args])
return completed_proc.returncode

import shlex

Expand All @@ -81,9 +93,6 @@ def activate(self, env: "VirtualEnv") -> Optional[int]:
if self._name == "zsh":
c.setecho(False)

activate_script = self._get_activate_script()
bin_dir = "Scripts" if WINDOWS else "bin"
activate_path = env.path / bin_dir / activate_script
c.sendline(f"{self._get_source_command()} {shlex.quote(str(activate_path))}")

def resize(sig: Any, data: Any) -> None:
Expand All @@ -103,6 +112,10 @@ def _get_activate_script(self) -> str:
suffix = ".fish"
elif self._name in ("csh", "tcsh"):
suffix = ".csh"
elif self._name in ("powershell", "pwsh"):
suffix = ".ps1"
elif self._name == "cmd":
suffix = ".bat"
else:
suffix = ""

Expand Down