Skip to content

Commit 28d05d0

Browse files
authored
adds better windows shell support (#5053)
* adds better windows shell support * Updates per review uses subprocess.run() adds support for pwsh * changes how command list is built
1 parent 335f209 commit 28d05d0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/poetry/utils/shell.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import signal
3+
import subprocess
34
import sys
45

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

6970
def activate(self, env: "VirtualEnv") -> Optional[int]:
71+
activate_script = self._get_activate_script()
72+
bin_dir = "Scripts" if WINDOWS else "bin"
73+
activate_path = env.path / bin_dir / activate_script
74+
7075
if WINDOWS:
71-
return env.execute(self.path)
76+
if self._name in ("powershell", "pwsh"):
77+
args = ["-NoExit", "-File", str(activate_path)]
78+
else:
79+
# /K will execute the bat file and
80+
# keep the cmd process from terminating
81+
args = ["/K", str(activate_path)]
82+
completed_proc = subprocess.run([self.path, *args])
83+
return completed_proc.returncode
7284

7385
import shlex
7486

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

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

8998
def resize(sig: Any, data: Any) -> None:
@@ -103,6 +112,10 @@ def _get_activate_script(self) -> str:
103112
suffix = ".fish"
104113
elif self._name in ("csh", "tcsh"):
105114
suffix = ".csh"
115+
elif self._name in ("powershell", "pwsh"):
116+
suffix = ".ps1"
117+
elif self._name == "cmd":
118+
suffix = ".bat"
106119
else:
107120
suffix = ""
108121

0 commit comments

Comments
 (0)