##// END OF EJS Templates
Add message when trying to %load_ext a module that is not an IPython extension.
Thomas Kluyver -
Show More
@@ -87,7 +87,8 b' class ExtensionManager(Configurable):'
87 87 """Load an IPython extension by its module name.
88 88
89 89 Returns the string "already loaded" if the extension is already loaded,
90 otherwise None.
90 "no load function" if the module doesn't have a load_ipython_extension
91 function, or None if it succeeded.
91 92 """
92 93 if module_str in self.loaded:
93 94 return "already loaded"
@@ -100,6 +101,8 b' class ExtensionManager(Configurable):'
100 101 mod = sys.modules[module_str]
101 102 if self._call_load_ipython_extension(mod):
102 103 self.loaded.add(module_str)
104 else:
105 return "no load function"
103 106
104 107 def unload_extension(self, module_str):
105 108 """Unload an IPython extension by its module name.
@@ -59,9 +59,13 b' class ExtensionMagics(Magics):'
59 59 """Load an IPython extension by its module name."""
60 60 if not module_str:
61 61 raise UsageError('Missing module name.')
62 if self.shell.extension_manager.load_extension(module_str) == 'already loaded':
62 res = self.shell.extension_manager.load_extension(module_str)
63
64 if res == 'already loaded':
63 65 print "The %s extension is already loaded. To reload it, use:" % module_str
64 66 print " %reload_ext", module_str
67 elif res == 'no load function':
68 print "The %s module is not an IPython extension." % module_str
65 69
66 70 @line_magic
67 71 def unload_ext(self, module_str):
@@ -67,3 +67,7 b' def test_extension_loading():'
67 67 # But can reload it
68 68 with tt.AssertPrints("Running ext2 load"):
69 69 em.reload_extension('ext2')
70
71 def test_non_extension():
72 em = get_ipython().extension_manager
73 nt.assert_equal(em.load_extension('sys'), "no load function")
General Comments 0
You need to be logged in to leave comments. Login now