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