Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

skip find_cmd when setting up script magics #2424

Merged
merged 2 commits into from

4 participants

@minrk
Owner

find_cmd was slowing down process startup, and probably unnecessary anyway.

minrk added some commits
@minrk minrk skip find_cmd when setting up script magics
find_cmd was slow, and probably unnecessary anyway.
40041f6
@minrk minrk better message on script magic not found
More relevant now that we register default script magics that probably don't exist.
0556f3b
@fperez
Owner

@jasongrout, would you mind giving this PR a quick test? It would be good to know if it improves your startup situation in any significant way...

@jasongrout

It does seem to make a difference. Thanks!

@jasongrout

to be precise, it cuts our startup time in about 1/2.

@Carreau
Owner

As it seem to do it's job, and speed up startup a lot, i'm going to merge this guy.

@Carreau Carreau merged commit cfe1161 into from
@minrk minrk deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 23, 2012
  1. @minrk

    skip find_cmd when setting up script magics

    minrk authored
    find_cmd was slow, and probably unnecessary anyway.
  2. @minrk

    better message on script magic not found

    minrk authored
    More relevant now that we register default script magics that probably don't exist.
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 25 deletions.
  1. +20 −25 IPython/core/magics/script.py
View
45 IPython/core/magics/script.py
@@ -12,6 +12,7 @@
#-----------------------------------------------------------------------------
# Stdlib
+import errno
import os
import re
import sys
@@ -30,7 +31,7 @@
from IPython.lib.backgroundjobs import BackgroundJobManager
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import py3compat
-from IPython.utils.process import find_cmd, FindCmdError, arg_split
+from IPython.utils.process import arg_split
from IPython.utils.traitlets import List, Dict
#-----------------------------------------------------------------------------
@@ -90,36 +91,23 @@ class ScriptMagics(Magics, Configurable):
""",
)
def _script_magics_default(self):
- """default to a common list of programs if we find them"""
+ """default to a common list of programs"""
- defaults = []
- to_try = []
- if os.name == 'nt':
- defaults.append('cmd')
- to_try.append('powershell')
- to_try.extend([
+ defaults = [
'sh',
'bash',
'perl',
'ruby',
+ 'python',
'python3',
'pypy',
- ])
+ ]
+ if os.name == 'nt':
+ defaults.extend([
+ 'cmd',
+ 'powershell',
+ ])
- for cmd in to_try:
- if cmd in self.script_paths:
- defaults.append(cmd)
- else:
- try:
- find_cmd(cmd)
- except FindCmdError:
- # command not found, ignore it
- pass
- except ImportError:
- # Windows without pywin32, find_cmd doesn't work
- pass
- else:
- defaults.append(cmd)
return defaults
script_paths = Dict(config=True,
@@ -197,8 +185,15 @@ def shebang(self, line, cell):
"""
argv = arg_split(line, posix = not sys.platform.startswith('win'))
args, cmd = self.shebang.parser.parse_known_args(argv)
-
- p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
+
+ try:
+ p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ print "Couldn't find program: %r" % cmd[0]
+ return
+ else:
+ raise
cell = cell.encode('utf8', 'replace')
if args.bg:
Something went wrong with that request. Please try again.