Skip to content

Commit

Permalink
adds better windows shell support
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarroquin committed Jan 17, 2022
1 parent a358be7 commit 57450f2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 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,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

Expand All @@ -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:
Expand All @@ -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 = ""

Expand Down

0 comments on commit 57450f2

Please sign in to comment.