diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 9398518..c70a2ee 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -117,9 +117,10 @@ class InteractiveShellApp(Configurable): Provides configurables for loading extensions and executing files as part of configuring a Shell environment. - - Provides init_extensions() and init_code() methods, to be called - after init_shell(), which must be implemented by subclasses. + + Provides init_path(), to be called before, and init_extensions() and + init_code() methods, to be called after init_shell(), which must be + implemented by subclasses. """ extensions = List(Unicode, config=True, help="A list of dotted module names of IPython extensions to load." @@ -156,6 +157,11 @@ class InteractiveShellApp(Configurable): ) shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') + def init_path(self): + """Add current working directory, '', to sys.path""" + if sys.path[0] != '': + sys.path.insert(0, '') + def init_shell(self): raise NotImplementedError("Override in subclasses") diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index 8b68772..f2335d6 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -314,6 +314,7 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): # print self.extra_args if self.extra_args and not self.something_to_run: self.file_to_run = self.extra_args[0] + self.init_path() # create the shell self.init_shell() # and draw the banner @@ -325,10 +326,6 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): def init_shell(self): """initialize the InteractiveShell instance""" - # I am a little hesitant to put these into InteractiveShell itself. - # But that might be the place for them - sys.path.insert(0, '') - # Create an InteractiveShell instance. # shell.display_banner should always be False for the terminal # based app, because we call shell.show_banner() by hand below diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 2f74ded..d57103a 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -597,6 +597,7 @@ class IPKernelApp(KernelApp, InteractiveShellApp): @catch_config_error def initialize(self, argv=None): super(IPKernelApp, self).initialize(argv) + self.init_path() self.init_shell() self.init_extensions() self.init_code() @@ -640,10 +641,6 @@ class IPKernelApp(KernelApp, InteractiveShellApp): def init_shell(self): - # I am a little hesitant to put these into InteractiveShell itself. - # But that might be the place for them - sys.path.insert(0, '') - self.shell = self.kernel.shell self.shell.configurables.append(self)