Permalink
Browse files

Add message when trying to %load_ext a module that is not an IPython …

…extension.
  • Loading branch information...
1 parent 6b078ed commit ef172ee57ec92b22e7e8e5905ac033ac810fed2e @takluyver committed Oct 17, 2012
Showing with 13 additions and 2 deletions.
  1. +4 −1 IPython/core/extensions.py
  2. +5 −1 IPython/core/magics/extension.py
  3. +4 −0 IPython/core/tests/test_extension.py
@@ -87,7 +87,8 @@ def load_extension(self, module_str):
"""Load an IPython extension by its module name.
Returns the string "already loaded" if the extension is already loaded,
- otherwise None.
+ "no load function" if the module doesn't have a load_ipython_extension
+ function, or None if it succeeded.
"""
if module_str in self.loaded:
return "already loaded"
@@ -100,6 +101,8 @@ def load_extension(self, module_str):
mod = sys.modules[module_str]
if self._call_load_ipython_extension(mod):
self.loaded.add(module_str)
+ else:
+ return "no load function"
def unload_extension(self, module_str):
"""Unload an IPython extension by its module name.
@@ -59,9 +59,13 @@ def load_ext(self, module_str):
"""Load an IPython extension by its module name."""
if not module_str:
raise UsageError('Missing module name.')
- if self.shell.extension_manager.load_extension(module_str) == 'already loaded':
+ res = self.shell.extension_manager.load_extension(module_str)
+
+ if res == 'already loaded':
print "The %s extension is already loaded. To reload it, use:" % module_str
print " %reload_ext", module_str
+ elif res == 'no load function':
+ print "The %s module is not an IPython extension." % module_str
@line_magic
def unload_ext(self, module_str):
@@ -67,3 +67,7 @@ def test_extension_loading():
# But can reload it
with tt.AssertPrints("Running ext2 load"):
em.reload_extension('ext2')
+
+def test_non_extension():
+ em = get_ipython().extension_manager
+ nt.assert_equal(em.load_extension('sys'), "no load function")

0 comments on commit ef172ee

Please sign in to comment.