14
14
import threading
15
15
from subprocess import Popen
16
16
from collections import namedtuple
17
+ from platform import system
17
18
18
19
19
20
Package = namedtuple ("Package" , ["name" , "url" , "import_name" ])
@@ -126,7 +127,7 @@ def use_template(packages):
126
127
127
128
:param list packages: the name of the packages to import
128
129
129
- :returns: the path to the created template file
130
+ :returns: the path to the created tempkate file
130
131
:rtype: str
131
132
"""
132
133
with open (os .path .join (os .path .dirname (__file__ ), "script.template" )) as template_file :
@@ -146,7 +147,10 @@ def pip_install(package, index=None):
146
147
147
148
def run_shell (shell , startup_script ):
148
149
"""Run specific python shell."""
149
- exec_in_virtualenv ("PYTHONSTARTUP={0} {1}" .format (startup_script , shell ))
150
+ if system () == "Windows" :
151
+ exec_in_virtualenv ("PYTHONSTARTUP={0} && {1}" .format (startup_script , shell ))
152
+ else :
153
+ exec_in_virtualenv ("PYTHONSTARTUP={0} {1}" .format (startup_script , shell ))
150
154
151
155
152
156
def run_editor (template_path ):
@@ -157,7 +161,13 @@ def run_editor(template_path):
157
161
158
162
def exec_in_virtualenv (command ):
159
163
"""Execute command in virtualenv."""
160
- proc = Popen (". {0}/bin/activate && {1}" .format (context .virtualenv_path , command ), shell = True )
164
+ if system () == "Windows" :
165
+ if command .startswith ("PYTHONSTARTUP" ):
166
+ proc = Popen ("{0}/Scripts/activate && set {1}" .format (context .virtualenv_path , command ), shell = True )
167
+ else :
168
+ proc = Popen ("{0}/Scripts/activate && {1}" .format (context .virtualenv_path , command ), shell = True )
169
+ else :
170
+ proc = Popen (". {0}/bin/activate && {1}" .format (context .virtualenv_path , command ), shell = True )
161
171
if proc .wait () != 0 :
162
172
raise TryError ("Command '{0}' exited with error code: {1}. See {2}" .format (
163
173
command , proc .returncode , context .logfile ))
0 commit comments