Show More
@@ -42,28 +42,15 b' class ExtensionManager(Configurable):' | |||
|
42 | 42 | if the extension is reloaded. |
|
43 | 43 | |
|
44 | 44 | You can put your extension modules anywhere you want, as long as |
|
45 |
they can be imported by Python's standard import mechanism. |
|
|
46 | to make it easy to write extensions, you can also put your extensions | |
|
47 | in ``os.path.join(self.ipython_dir, 'extensions')``. This directory | |
|
48 | is added to ``sys.path`` automatically. | |
|
45 | they can be imported by Python's standard import mechanism. | |
|
49 | 46 | """ |
|
50 | 47 | |
|
51 | 48 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True) |
|
52 | 49 | |
|
53 | 50 | def __init__(self, shell=None, **kwargs): |
|
54 | 51 | super(ExtensionManager, self).__init__(shell=shell, **kwargs) |
|
55 | self.shell.observe( | |
|
56 | self._on_ipython_dir_changed, names=('ipython_dir',) | |
|
57 | ) | |
|
58 | 52 | self.loaded = set() |
|
59 | 53 | |
|
60 | @property | |
|
61 | def ipython_extension_dir(self): | |
|
62 | return os.path.join(self.shell.ipython_dir, u'extensions') | |
|
63 | ||
|
64 | def _on_ipython_dir_changed(self, change): | |
|
65 | ensure_dir_exists(self.ipython_extension_dir) | |
|
66 | ||
|
67 | 54 | def load_extension(self, module_str: str): |
|
68 | 55 | """Load an IPython extension by its module name. |
|
69 | 56 | |
@@ -124,7 +111,6 b' class ExtensionManager(Configurable):' | |||
|
124 | 111 | :func:`reload` is called and then the :func:`load_ipython_extension` |
|
125 | 112 | function of the module, if it exists is called. |
|
126 | 113 | """ |
|
127 | from IPython.utils.syspathcontext import prepended_to_syspath | |
|
128 | 114 | |
|
129 | 115 | if BUILTINS_EXTS.get(module_str, False) is True: |
|
130 | 116 | module_str = "IPython.extensions." + module_str |
@@ -132,8 +118,7 b' class ExtensionManager(Configurable):' | |||
|
132 | 118 | if (module_str in self.loaded) and (module_str in sys.modules): |
|
133 | 119 | self.unload_extension(module_str) |
|
134 | 120 | mod = sys.modules[module_str] |
|
135 | with prepended_to_syspath(self.ipython_extension_dir): | |
|
136 | reload(mod) | |
|
121 | reload(mod) | |
|
137 | 122 | if self._call_load_ipython_extension(mod): |
|
138 | 123 | self.loaded.add(module_str) |
|
139 | 124 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now