Commit 28d05d00 by Brian Marroquin Committed by GitHub

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
parent 335f209c
import os
import signal
import subprocess
import sys
from pathlib import Path
......@@ -67,8 +68,19 @@ class 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 @@ class Shell:
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 @@ class Shell:
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 = ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment