Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move sys.path.insert(0, '') from subclasses to InteractiveShellApp

  • Loading branch information...
commit 3ac6e9faae18d2644b2ce517b15c95dd6b7f57cb 1 parent 79e365b
@bfroehle authored
View
12 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 @@ def _extra_extension_changed(self, name, old, new):
)
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
+ def init_path(self):
+ """Add current working directory, '', to sys.path"""
+ if sys.path[0] != '':
@bfroehle Owner
bfroehle added a note

This test was required to prevent multiple instances of '' in ipython qtconsole and ipython console. I wasn't able to ascertain where the other entries were coming from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ sys.path.insert(0, '')
+
def init_shell(self):
raise NotImplementedError("Override in subclasses")
View
5 IPython/frontend/terminal/ipapp.py
@@ -314,6 +314,7 @@ def initialize(self, argv=None):
# 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 @@ def initialize(self, argv=None):
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
View
5 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 @@ def print_tb(etype, evalue, stb):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.