Skip to content

Commit

Permalink
adds better windows shell support (#5053)
Browse files Browse the repository at this point in the history
* adds better windows shell support

* Updates per review
uses subprocess.run()
adds support for pwsh

* changes how command list is built
  • Loading branch information
bmarroquin authored Jan 22, 2022
1 parent 335f209 commit 28d05d0
Showing 1 changed file with 17 additions and 4 deletions.
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)]
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

0 comments on commit 28d05d0

Please sign in to comment.