diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 8d81fde353d..7f01c00d830 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -1,5 +1,6 @@ import os import signal +import subprocess import sys from pathlib import Path @@ -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)] + 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 @@ -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: @@ -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 = ""