From 57450f2717da285eaf07f0a18d03ecc700e4938d Mon Sep 17 00:00:00 2001 From: Brian Marroquin Date: Mon, 17 Jan 2022 11:43:13 -0800 Subject: [PATCH 1/3] adds better windows shell support --- src/poetry/utils/shell.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 8d81fde353d..36b5ff5a03f 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,20 @@ 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 == "powershell": + 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)] + proc = subprocess.Popen([self.path] + args) + proc.communicate() + return proc.returncode import shlex @@ -81,9 +94,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 +113,10 @@ def _get_activate_script(self) -> str: suffix = ".fish" elif self._name in ("csh", "tcsh"): suffix = ".csh" + elif self._name == "powershell": + suffix = ".ps1" + elif self._name == "cmd": + suffix = ".bat" else: suffix = "" From c566e138e9b06a1ba0a26f4e3629ae0ea77ac70d Mon Sep 17 00:00:00 2001 From: Brian Marroquin Date: Tue, 18 Jan 2022 19:37:38 -0800 Subject: [PATCH 2/3] Updates per review uses subprocess.run() adds support for pwsh --- src/poetry/utils/shell.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 36b5ff5a03f..43e9591a7e6 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -73,15 +73,14 @@ def activate(self, env: "VirtualEnv") -> Optional[int]: activate_path = env.path / bin_dir / activate_script if WINDOWS: - if self._name == "powershell": + 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)] - proc = subprocess.Popen([self.path] + args) - proc.communicate() - return proc.returncode + completed_proc = subprocess.run([self.path] + args) + return completed_proc.returncode import shlex @@ -113,7 +112,7 @@ def _get_activate_script(self) -> str: suffix = ".fish" elif self._name in ("csh", "tcsh"): suffix = ".csh" - elif self._name == "powershell": + elif self._name in ("powershell", "pwsh"): suffix = ".ps1" elif self._name == "cmd": suffix = ".bat" From e3fae84700f29c809c709e822f3c47b61df43a7f Mon Sep 17 00:00:00 2001 From: Brian Marroquin Date: Fri, 21 Jan 2022 18:10:52 -0800 Subject: [PATCH 3/3] changes how command list is built --- src/poetry/utils/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 43e9591a7e6..7f01c00d830 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -79,7 +79,7 @@ def activate(self, env: "VirtualEnv") -> Optional[int]: # /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) + completed_proc = subprocess.run([self.path, *args]) return completed_proc.returncode import shlex