##// END OF EJS Templates
Add a set to track what extensions are loaded.
Thomas Kluyver -
Show More
@@ -63,6 +63,7 b' class ExtensionManager(Configurable):'
63 self.shell.on_trait_change(
63 self.shell.on_trait_change(
64 self._on_ipython_dir_changed, 'ipython_dir'
64 self._on_ipython_dir_changed, 'ipython_dir'
65 )
65 )
66 self.loaded = set()
66
67
67 def __del__(self):
68 def __del__(self):
68 self.shell.on_trait_change(
69 self.shell.on_trait_change(
@@ -89,7 +90,8 b' class ExtensionManager(Configurable):'
89 with prepended_to_syspath(self.ipython_extension_dir):
90 with prepended_to_syspath(self.ipython_extension_dir):
90 __import__(module_str)
91 __import__(module_str)
91 mod = sys.modules[module_str]
92 mod = sys.modules[module_str]
92 return self._call_load_ipython_extension(mod)
93 if self._call_load_ipython_extension(mod):
94 self.loaded.add(module_str)
93
95
94 def unload_extension(self, module_str):
96 def unload_extension(self, module_str):
95 """Unload an IPython extension by its module name.
97 """Unload an IPython extension by its module name.
@@ -99,7 +101,8 b' class ExtensionManager(Configurable):'
99 """
101 """
100 if module_str in sys.modules:
102 if module_str in sys.modules:
101 mod = sys.modules[module_str]
103 mod = sys.modules[module_str]
102 self._call_unload_ipython_extension(mod)
104 if self._call_unload_ipython_extension(mod):
105 self.loaded.discard(module_str)
103
106
104 def reload_extension(self, module_str):
107 def reload_extension(self, module_str):
105 """Reload an IPython extension by calling reload.
108 """Reload an IPython extension by calling reload.
@@ -121,11 +124,13 b' class ExtensionManager(Configurable):'
121
124
122 def _call_load_ipython_extension(self, mod):
125 def _call_load_ipython_extension(self, mod):
123 if hasattr(mod, 'load_ipython_extension'):
126 if hasattr(mod, 'load_ipython_extension'):
124 return mod.load_ipython_extension(self.shell)
127 mod.load_ipython_extension(self.shell)
128 return True
125
129
126 def _call_unload_ipython_extension(self, mod):
130 def _call_unload_ipython_extension(self, mod):
127 if hasattr(mod, 'unload_ipython_extension'):
131 if hasattr(mod, 'unload_ipython_extension'):
128 return mod.unload_ipython_extension(self.shell)
132 mod.unload_ipython_extension(self.shell)
133 return True
129
134
130 def install_extension(self, url, filename=None):
135 def install_extension(self, url, filename=None):
131 """Download and install an IPython extension.
136 """Download and install an IPython extension.
@@ -59,7 +59,7 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 return self.shell.extension_manager.load_extension(module_str)
62 self.shell.extension_manager.load_extension(module_str)
63
63
64 @line_magic
64 @line_magic
65 def unload_ext(self, module_str):
65 def unload_ext(self, module_str):
General Comments 0
You need to be logged in to leave comments. Login now