Show More
@@ -55,7 +55,6 b' from IPython.core.inputsplitter import IPythonInputSplitter, ESC_MAGIC, ESC_MAGI' | |||
|
55 | 55 | from IPython.core.logger import Logger |
|
56 | 56 | from IPython.core.macro import Macro |
|
57 | 57 | from IPython.core.payload import PayloadManager |
|
58 | from IPython.core.plugin import PluginManager | |
|
59 | 58 | from IPython.core.prefilter import PrefilterManager |
|
60 | 59 | from IPython.core.profiledir import ProfileDir |
|
61 | 60 | from IPython.core.pylabtools import pylab_activate |
@@ -386,7 +385,6 b' class InteractiveShell(SingletonConfigurable):' | |||
|
386 | 385 | builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap') |
|
387 | 386 | display_trap = Instance('IPython.core.display_trap.DisplayTrap') |
|
388 | 387 | extension_manager = Instance('IPython.core.extensions.ExtensionManager') |
|
389 | plugin_manager = Instance('IPython.core.plugin.PluginManager') | |
|
390 | 388 | payload_manager = Instance('IPython.core.payload.PayloadManager') |
|
391 | 389 | history_manager = Instance('IPython.core.history.HistoryManager') |
|
392 | 390 | magics_manager = Instance('IPython.core.magic.MagicsManager') |
@@ -486,7 +484,6 b' class InteractiveShell(SingletonConfigurable):' | |||
|
486 | 484 | self.init_logstart() |
|
487 | 485 | self.init_pdb() |
|
488 | 486 | self.init_extension_manager() |
|
489 | self.init_plugin_manager() | |
|
490 | 487 | self.init_payload() |
|
491 | 488 | self.hooks.late_startup_hook() |
|
492 | 489 | atexit.register(self.atexit_operations) |
@@ -2282,18 +2279,13 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2282 | 2279 | self.ns_table['alias'] = self.alias_manager.alias_table, |
|
2283 | 2280 | |
|
2284 | 2281 | #------------------------------------------------------------------------- |
|
2285 |
# Things related to extensions |
|
|
2282 | # Things related to extensions | |
|
2286 | 2283 | #------------------------------------------------------------------------- |
|
2287 | 2284 | |
|
2288 | 2285 | def init_extension_manager(self): |
|
2289 | 2286 | self.extension_manager = ExtensionManager(shell=self, config=self.config) |
|
2290 | 2287 | self.configurables.append(self.extension_manager) |
|
2291 | 2288 | |
|
2292 | def init_plugin_manager(self): | |
|
2293 | self.plugin_manager = PluginManager(config=self.config) | |
|
2294 | self.configurables.append(self.plugin_manager) | |
|
2295 | ||
|
2296 | ||
|
2297 | 2289 | #------------------------------------------------------------------------- |
|
2298 | 2290 | # Things related to payloads |
|
2299 | 2291 | #------------------------------------------------------------------------- |
@@ -106,13 +106,10 b' skip_doctest = True' | |||
|
106 | 106 | #----------------------------------------------------------------------------- |
|
107 | 107 | # Imports |
|
108 | 108 | #----------------------------------------------------------------------------- |
|
109 | import atexit | |
|
109 | ||
|
110 | 110 | import imp |
|
111 | import inspect | |
|
112 | 111 | import os |
|
113 | 112 | import sys |
|
114 | import threading | |
|
115 | import time | |
|
116 | 113 | import traceback |
|
117 | 114 | import types |
|
118 | 115 | import weakref |
@@ -409,7 +406,6 b' def superreload(module, reload=reload, old_objects={}):' | |||
|
409 | 406 | |
|
410 | 407 | from IPython.core.hooks import TryNext |
|
411 | 408 | from IPython.core.magic import Magics, magics_class, line_magic |
|
412 | from IPython.core.plugin import Plugin | |
|
413 | 409 | |
|
414 | 410 | @magics_class |
|
415 | 411 | class AutoreloadMagics(Magics): |
@@ -518,14 +514,6 b' class AutoreloadMagics(Magics):' | |||
|
518 | 514 | pass |
|
519 | 515 | |
|
520 | 516 | |
|
521 | class AutoreloadPlugin(Plugin): | |
|
522 | def __init__(self, shell=None, config=None): | |
|
523 | super(AutoreloadPlugin, self).__init__(shell=shell, config=config) | |
|
524 | self.auto_magics = AutoreloadMagics(shell) | |
|
525 | shell.register_magics(self.auto_magics) | |
|
526 | shell.set_hook('pre_run_code_hook', self.auto_magics.pre_run_code_hook) | |
|
527 | ||
|
528 | ||
|
529 | 517 | _loaded = False |
|
530 | 518 | |
|
531 | 519 | |
@@ -533,6 +521,7 b' def load_ipython_extension(ip):' | |||
|
533 | 521 | """Load the extension in IPython.""" |
|
534 | 522 | global _loaded |
|
535 | 523 | if not _loaded: |
|
536 | plugin = AutoreloadPlugin(shell=ip, config=ip.config) | |
|
537 |
ip. |
|
|
524 | auto_reload = AutoreloadMagics(ip) | |
|
525 | ip.register_magics(auto_reload) | |
|
526 | ip.set_hook('pre_run_code_hook', auto_reload.pre_run_code_hook) | |
|
538 | 527 | _loaded = True |
@@ -28,9 +28,7 b' import inspect, os, sys, textwrap' | |||
|
28 | 28 | from IPython.core.error import UsageError |
|
29 | 29 | from IPython.core.fakemodule import FakeModule |
|
30 | 30 | from IPython.core.magic import Magics, magics_class, line_magic |
|
31 | from IPython.core.plugin import Plugin | |
|
32 | 31 | from IPython.testing.skipdoctest import skip_doctest |
|
33 | from IPython.utils.traitlets import Bool, Instance | |
|
34 | 32 | |
|
35 | 33 | #----------------------------------------------------------------------------- |
|
36 | 34 | # Functions and classes |
@@ -211,24 +209,12 b' class StoreMagics(Magics):' | |||
|
211 | 209 | print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) |
|
212 | 210 | |
|
213 | 211 | |
|
214 | class StoreMagic(Plugin): | |
|
215 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
|
216 | autorestore = Bool(False, config=True) | |
|
217 | ||
|
218 | def __init__(self, shell, config): | |
|
219 | super(StoreMagic, self).__init__(shell=shell, config=config) | |
|
220 | shell.register_magics(StoreMagics) | |
|
221 | ||
|
222 | if self.autorestore: | |
|
223 | restore_data(shell) | |
|
224 | ||
|
225 | ||
|
226 | 212 | _loaded = False |
|
227 | 213 | |
|
214 | ||
|
228 | 215 | def load_ipython_extension(ip): |
|
229 | 216 | """Load the extension in IPython.""" |
|
230 | 217 | global _loaded |
|
231 | 218 | if not _loaded: |
|
232 | plugin = StoreMagic(shell=ip, config=ip.config) | |
|
233 | ip.plugin_manager.register_plugin('storemagic', plugin) | |
|
219 | ip.register_magics(StoreMagics) | |
|
234 | 220 | _loaded = True |
@@ -23,7 +23,7 b' from StringIO import StringIO' | |||
|
23 | 23 | import nose.tools as nt |
|
24 | 24 | import IPython.testing.tools as tt |
|
25 | 25 | |
|
26 |
from IPython.extensions.autoreload import Autoreload |
|
|
26 | from IPython.extensions.autoreload import AutoreloadMagics | |
|
27 | 27 | from IPython.core.hooks import TryNext |
|
28 | 28 | |
|
29 | 29 | #----------------------------------------------------------------------------- |
@@ -35,13 +35,13 b' noop = lambda *a, **kw: None' | |||
|
35 | 35 | class FakeShell(object): |
|
36 | 36 | def __init__(self): |
|
37 | 37 | self.ns = {} |
|
38 |
self. |
|
|
38 | self.auto_magics = AutoreloadMagics(shell=self) | |
|
39 | 39 | |
|
40 | 40 | register_magics = set_hook = noop |
|
41 | 41 | |
|
42 | 42 | def run_code(self, code): |
|
43 | 43 | try: |
|
44 |
self |
|
|
44 | self.auto_magics.pre_run_code_hook(self) | |
|
45 | 45 | except TryNext: |
|
46 | 46 | pass |
|
47 | 47 | exec code in self.ns |
@@ -50,10 +50,10 b' class FakeShell(object):' | |||
|
50 | 50 | self.ns.update(items) |
|
51 | 51 | |
|
52 | 52 | def magic_autoreload(self, parameter): |
|
53 |
self |
|
|
53 | self.auto_magics.autoreload(parameter) | |
|
54 | 54 | |
|
55 | 55 | def magic_aimport(self, parameter, stream=None): |
|
56 |
self |
|
|
56 | self.auto_magics.aimport(parameter, stream=stream) | |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | class Fixture(object): |
@@ -72,7 +72,6 b' class Fixture(object):' | |||
|
72 | 72 | def tearDown(self): |
|
73 | 73 | shutil.rmtree(self.test_dir) |
|
74 | 74 | sys.path = self.old_sys_path |
|
75 | self.shell.reloader.enabled = False | |
|
76 | 75 | |
|
77 | 76 | self.test_dir = None |
|
78 | 77 | self.old_sys_path = None |
@@ -43,7 +43,7 b' functions to load and unload it. Here is a template::' | |||
|
43 | 43 | def load_ipython_extension(ipython): |
|
44 | 44 | # The `ipython` argument is the currently active `InteractiveShell` |
|
45 | 45 | # instance, which can be used in any way. This allows you to register |
|
46 |
# new magics |
|
|
46 | # new magics or aliases, for example. | |
|
47 | 47 | |
|
48 | 48 | def unload_ipython_extension(ipython): |
|
49 | 49 | # If you want your extension to be unloadable, put that logic here. |
@@ -70,29 +70,6 b' write extensions, you can also put your extensions in' | |||
|
70 | 70 | When your extension is ready for general use, please add it to the `extensions |
|
71 | 71 | index <http://wiki.ipython.org/Extensions_Index>`_. |
|
72 | 72 | |
|
73 | Plugin class | |
|
74 | ------------ | |
|
75 | ||
|
76 | More advanced extensions might want to subclass :class:`IPython.core.plugin.Plugin`. | |
|
77 | A plugin can have options configured by IPython's main :ref:`configuration | |
|
78 | system <config_overview>`. The code to load and unload it looks like this:: | |
|
79 | ||
|
80 | def load_ipython_extension(ip): | |
|
81 | """Load the plugin in IPython.""" | |
|
82 | plugin = MyPlugin(shell=ip, config=ip.config) | |
|
83 | try: | |
|
84 | ip.plugin_manager.register_plugin('myplugin', plugin) | |
|
85 | except KeyError: | |
|
86 | print("Already loaded") | |
|
87 | ||
|
88 | def unload_ipython_extension(ip): | |
|
89 | ip.plugin_manager.unregister_plugin('myplugin') | |
|
90 | ||
|
91 | For examples, see these files: | |
|
92 | ||
|
93 | * :file:`IPython/extensions/autoreload.py` | |
|
94 | * :file:`IPython/extensions/storemagic.py` | |
|
95 | ||
|
96 | 73 | .. _bundled_extensions: |
|
97 | 74 | |
|
98 | 75 | Extensions bundled with IPython |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now