##// END OF EJS Templates
hardcode builtins extensions
Matthias Bussonnier -
Show More
@@ -19,6 +19,9 b' from traitlets import Instance'
19 19 # Main class
20 20 #-----------------------------------------------------------------------------
21 21
22 BUILTINS_EXTS = {"storemagic": False, "autoreload": False}
23
24
22 25 class ExtensionManager(Configurable):
23 26 """A class to manage IPython extensions.
24 27
@@ -62,13 +65,22 b' class ExtensionManager(Configurable):'
62 65 def _on_ipython_dir_changed(self, change):
63 66 ensure_dir_exists(self.ipython_extension_dir)
64 67
65 def load_extension(self, module_str):
68 def load_extension(self, module_str: str):
66 69 """Load an IPython extension by its module name.
67 70
68 71 Returns the string "already loaded" if the extension is already loaded,
69 72 "no load function" if the module doesn't have a load_ipython_extension
70 73 function, or None if it succeeded.
71 74 """
75 try:
76 return self._load_extension(module_str)
77 except ModuleNotFoundError:
78 if module_str in BUILTINS_EXTS:
79 BUILTINS_EXTS[module_str] = True
80 return self._load_extension("IPython.extensions." + module_str)
81 raise
82
83 def _load_extension(self, module_str: str):
72 84 if module_str in self.loaded:
73 85 return "already loaded"
74 86
@@ -89,7 +101,7 b' class ExtensionManager(Configurable):'
89 101 else:
90 102 return "no load function"
91 103
92 def unload_extension(self, module_str):
104 def unload_extension(self, module_str: str):
93 105 """Unload an IPython extension by its module name.
94 106
95 107 This function looks up the extension's name in ``sys.modules`` and
@@ -99,9 +111,11 b' class ExtensionManager(Configurable):'
99 111 a function to unload itself, "not loaded" if the extension isn't loaded,
100 112 otherwise None.
101 113 """
114 if BUILTINS_EXTS.get(module_str, False) is True:
115 module_str = "IPython.extensions." + module_str
102 116 if module_str not in self.loaded:
103 117 return "not loaded"
104
118
105 119 if module_str in sys.modules:
106 120 mod = sys.modules[module_str]
107 121 if self._call_unload_ipython_extension(mod):
@@ -109,7 +123,7 b' class ExtensionManager(Configurable):'
109 123 else:
110 124 return "no unload function"
111 125
112 def reload_extension(self, module_str):
126 def reload_extension(self, module_str: str):
113 127 """Reload an IPython extension by calling reload.
114 128
115 129 If the module has not been loaded before,
@@ -119,6 +133,9 b' class ExtensionManager(Configurable):'
119 133 """
120 134 from IPython.utils.syspathcontext import prepended_to_syspath
121 135
136 if BUILTINS_EXTS.get(module_str, False) is True:
137 module_str = "IPython.extensions." + module_str
138
122 139 if (module_str in self.loaded) and (module_str in sys.modules):
123 140 self.unload_extension(module_str)
124 141 mod = sys.modules[module_str]
General Comments 0
You need to be logged in to leave comments. Login now