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