1
1
import os
2
2
import signal
3
+ import subprocess
3
4
import sys
4
5
5
6
from pathlib import Path
@@ -67,8 +68,19 @@ def get(cls) -> "Shell":
67
68
return cls ._shell
68
69
69
70
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
+
70
75
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
72
84
73
85
import shlex
74
86
@@ -81,9 +93,6 @@ def activate(self, env: "VirtualEnv") -> Optional[int]:
81
93
if self ._name == "zsh" :
82
94
c .setecho (False )
83
95
84
- activate_script = self ._get_activate_script ()
85
- bin_dir = "Scripts" if WINDOWS else "bin"
86
- activate_path = env .path / bin_dir / activate_script
87
96
c .sendline (f"{ self ._get_source_command ()} { shlex .quote (str (activate_path ))} " )
88
97
89
98
def resize (sig : Any , data : Any ) -> None :
@@ -103,6 +112,10 @@ def _get_activate_script(self) -> str:
103
112
suffix = ".fish"
104
113
elif self ._name in ("csh" , "tcsh" ):
105
114
suffix = ".csh"
115
+ elif self ._name in ("powershell" , "pwsh" ):
116
+ suffix = ".ps1"
117
+ elif self ._name == "cmd" :
118
+ suffix = ".bat"
106
119
else :
107
120
suffix = ""
108
121
0 commit comments