##// END OF EJS Templates
Merge pull request #2424 from minrk/fastscript...
Bussonnier Matthias -
r8504:cfe1161c merge
parent child Browse files
Show More
@@ -12,6 +12,7 b''
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 # Stdlib
14 # Stdlib
15 import errno
15 import os
16 import os
16 import re
17 import re
17 import sys
18 import sys
@@ -30,7 +31,7 b' from IPython.core.magic import ('
30 from IPython.lib.backgroundjobs import BackgroundJobManager
31 from IPython.lib.backgroundjobs import BackgroundJobManager
31 from IPython.testing.skipdoctest import skip_doctest
32 from IPython.testing.skipdoctest import skip_doctest
32 from IPython.utils import py3compat
33 from IPython.utils import py3compat
33 from IPython.utils.process import find_cmd, FindCmdError, arg_split
34 from IPython.utils.process import arg_split
34 from IPython.utils.traitlets import List, Dict
35 from IPython.utils.traitlets import List, Dict
35
36
36 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
@@ -90,36 +91,23 b' class ScriptMagics(Magics, Configurable):'
90 """,
91 """,
91 )
92 )
92 def _script_magics_default(self):
93 def _script_magics_default(self):
93 """default to a common list of programs if we find them"""
94 """default to a common list of programs"""
94
95
95 defaults = []
96 defaults = [
96 to_try = []
97 if os.name == 'nt':
98 defaults.append('cmd')
99 to_try.append('powershell')
100 to_try.extend([
101 'sh',
97 'sh',
102 'bash',
98 'bash',
103 'perl',
99 'perl',
104 'ruby',
100 'ruby',
101 'python',
105 'python3',
102 'python3',
106 'pypy',
103 'pypy',
107 ])
104 ]
105 if os.name == 'nt':
106 defaults.extend([
107 'cmd',
108 'powershell',
109 ])
108
110
109 for cmd in to_try:
110 if cmd in self.script_paths:
111 defaults.append(cmd)
112 else:
113 try:
114 find_cmd(cmd)
115 except FindCmdError:
116 # command not found, ignore it
117 pass
118 except ImportError:
119 # Windows without pywin32, find_cmd doesn't work
120 pass
121 else:
122 defaults.append(cmd)
123 return defaults
111 return defaults
124
112
125 script_paths = Dict(config=True,
113 script_paths = Dict(config=True,
@@ -197,8 +185,15 b' class ScriptMagics(Magics, Configurable):'
197 """
185 """
198 argv = arg_split(line, posix = not sys.platform.startswith('win'))
186 argv = arg_split(line, posix = not sys.platform.startswith('win'))
199 args, cmd = self.shebang.parser.parse_known_args(argv)
187 args, cmd = self.shebang.parser.parse_known_args(argv)
200
188
201 p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
189 try:
190 p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
191 except OSError as e:
192 if e.errno == errno.ENOENT:
193 print "Couldn't find program: %r" % cmd[0]
194 return
195 else:
196 raise
202
197
203 cell = cell.encode('utf8', 'replace')
198 cell = cell.encode('utf8', 'replace')
204 if args.bg:
199 if args.bg:
General Comments 0
You need to be logged in to leave comments. Login now