Show More
@@ -87,7 +87,8 b' class ExtensionManager(Configurable):' | |||||
87 | """Load an IPython extension by its module name. |
|
87 | """Load an IPython extension by its module name. | |
88 |
|
88 | |||
89 | Returns the string "already loaded" if the extension is already loaded, |
|
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 | if module_str in self.loaded: |
|
93 | if module_str in self.loaded: | |
93 | return "already loaded" |
|
94 | return "already loaded" | |
@@ -100,6 +101,8 b' class ExtensionManager(Configurable):' | |||||
100 | mod = sys.modules[module_str] |
|
101 | mod = sys.modules[module_str] | |
101 | if self._call_load_ipython_extension(mod): |
|
102 | if self._call_load_ipython_extension(mod): | |
102 | self.loaded.add(module_str) |
|
103 | self.loaded.add(module_str) | |
|
104 | else: | |||
|
105 | return "no load function" | |||
103 |
|
106 | |||
104 | def unload_extension(self, module_str): |
|
107 | def unload_extension(self, module_str): | |
105 | """Unload an IPython extension by its module name. |
|
108 | """Unload an IPython extension by its module name. |
@@ -59,9 +59,13 b' class ExtensionMagics(Magics):' | |||||
59 | """Load an IPython extension by its module name.""" |
|
59 | """Load an IPython extension by its module name.""" | |
60 | if not module_str: |
|
60 | if not module_str: | |
61 | raise UsageError('Missing module name.') |
|
61 | raise UsageError('Missing module name.') | |
62 |
|
|
62 | res = self.shell.extension_manager.load_extension(module_str) | |
|
63 | ||||
|
64 | if res == 'already loaded': | |||
63 | print "The %s extension is already loaded. To reload it, use:" % module_str |
|
65 | print "The %s extension is already loaded. To reload it, use:" % module_str | |
64 | print " %reload_ext", module_str |
|
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 | @line_magic |
|
70 | @line_magic | |
67 | def unload_ext(self, module_str): |
|
71 | def unload_ext(self, module_str): |
@@ -67,3 +67,7 b' def test_extension_loading():' | |||||
67 | # But can reload it |
|
67 | # But can reload it | |
68 | with tt.AssertPrints("Running ext2 load"): |
|
68 | with tt.AssertPrints("Running ext2 load"): | |
69 | em.reload_extension('ext2') |
|
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