MCPcopy Create free account
hub / github.com/ipython/ipython / load_extension

Method load_extension

IPython/core/extensions.py:65–90  ·  view source on GitHub ↗

Load an IPython extension by its module name. Returns the string "already loaded" if the extension is already loaded, "no load function" if the module doesn't have a load_ipython_extension function, or None if it succeeded.

(self, module_str)

Source from the content-addressed store, hash-verified

63 ensure_dir_exists(self.ipython_extension_dir)
64
65 def load_extension(self, module_str):
66 """Load an IPython extension by its module name.
67
68 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
70 function, or None if it succeeded.
71 """
72 if module_str in self.loaded:
73 return "already loaded"
74
75 from IPython.utils.syspathcontext import prepended_to_syspath
76
77 with self.shell.builtin_trap:
78 if module_str not in sys.modules:
79 with prepended_to_syspath(self.ipython_extension_dir):
80 mod = import_module(module_str)
81 if mod.__file__.startswith(self.ipython_extension_dir):
82 print(("Loading extensions from {dir} is deprecated. "
83 "We recommend managing extensions like any "
84 "other Python packages, in site-packages.").format(
85 dir=compress_user(self.ipython_extension_dir)))
86 mod = sys.modules[module_str]
87 if self._call_load_ipython_extension(mod):
88 self.loaded.add(module_str)
89 else:
90 return "no load function"
91
92 def unload_extension(self, module_str):
93 """Unload an IPython extension by its module name.

Callers 6

reload_extensionMethod · 0.95
init_extensionsMethod · 0.80
test_extension_loadingFunction · 0.80
test_extension_builtinsFunction · 0.80
test_non_extensionFunction · 0.80
load_extMethod · 0.80

Calls 5

compress_userFunction · 0.90
formatMethod · 0.45
addMethod · 0.45

Tested by 3

test_extension_loadingFunction · 0.64
test_extension_builtinsFunction · 0.64
test_non_extensionFunction · 0.64