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