Skip to content

Commit 7070e72

Browse files
authored
ticket link - timofurrer#12
1 parent e277f8e commit 7070e72

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

trypackage/core.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import threading
1515
from subprocess import Popen
1616
from collections import namedtuple
17+
from platform import system
1718

1819

1920
Package = namedtuple("Package", ["name", "url", "import_name"])
@@ -126,7 +127,7 @@ def use_template(packages):
126127
127128
:param list packages: the name of the packages to import
128129
129-
:returns: the path to the created template file
130+
:returns: the path to the created tempkate file
130131
:rtype: str
131132
"""
132133
with open(os.path.join(os.path.dirname(__file__), "script.template")) as template_file:
@@ -146,7 +147,10 @@ def pip_install(package, index=None):
146147

147148
def run_shell(shell, startup_script):
148149
"""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))
150154

151155

152156
def run_editor(template_path):
@@ -157,7 +161,13 @@ def run_editor(template_path):
157161

158162
def exec_in_virtualenv(command):
159163
"""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)
161171
if proc.wait() != 0:
162172
raise TryError("Command '{0}' exited with error code: {1}. See {2}".format(
163173
command, proc.returncode, context.logfile))

0 commit comments

Comments
 (0)