diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 7a75c08..2f6c22e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -55,7 +55,6 @@ from IPython.core.inputsplitter import IPythonInputSplitter, ESC_MAGIC, ESC_MAGI from IPython.core.logger import Logger from IPython.core.macro import Macro from IPython.core.payload import PayloadManager -from IPython.core.plugin import PluginManager from IPython.core.prefilter import PrefilterManager from IPython.core.profiledir import ProfileDir from IPython.core.pylabtools import pylab_activate @@ -386,7 +385,6 @@ class InteractiveShell(SingletonConfigurable): builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap') display_trap = Instance('IPython.core.display_trap.DisplayTrap') extension_manager = Instance('IPython.core.extensions.ExtensionManager') - plugin_manager = Instance('IPython.core.plugin.PluginManager') payload_manager = Instance('IPython.core.payload.PayloadManager') history_manager = Instance('IPython.core.history.HistoryManager') magics_manager = Instance('IPython.core.magic.MagicsManager') @@ -486,7 +484,6 @@ class InteractiveShell(SingletonConfigurable): self.init_logstart() self.init_pdb() self.init_extension_manager() - self.init_plugin_manager() self.init_payload() self.hooks.late_startup_hook() atexit.register(self.atexit_operations) @@ -2282,18 +2279,13 @@ class InteractiveShell(SingletonConfigurable): self.ns_table['alias'] = self.alias_manager.alias_table, #------------------------------------------------------------------------- - # Things related to extensions and plugins + # Things related to extensions #------------------------------------------------------------------------- def init_extension_manager(self): self.extension_manager = ExtensionManager(shell=self, config=self.config) self.configurables.append(self.extension_manager) - def init_plugin_manager(self): - self.plugin_manager = PluginManager(config=self.config) - self.configurables.append(self.plugin_manager) - - #------------------------------------------------------------------------- # Things related to payloads #------------------------------------------------------------------------- diff --git a/IPython/core/plugin.py b/IPython/core/plugin.py deleted file mode 100644 index 4520b39..0000000 --- a/IPython/core/plugin.py +++ /dev/null @@ -1,51 +0,0 @@ -# encoding: utf-8 -"""IPython plugins. - -Authors: - -* Brian Granger -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from IPython.config.configurable import Configurable -from IPython.utils.traitlets import Dict - -#----------------------------------------------------------------------------- -# Main class -#----------------------------------------------------------------------------- - -class PluginManager(Configurable): - """A manager for IPython plugins.""" - - plugins = Dict({}) - - def __init__(self, config=None): - super(PluginManager, self).__init__(config=config) - - def register_plugin(self, name, plugin): - if not isinstance(plugin, Plugin): - raise TypeError('Expected Plugin, got: %r' % plugin) - if name in self.plugins: - raise KeyError('Plugin with name already exists: %r' % name) - self.plugins[name] = plugin - - def unregister_plugin(self, name): - del self.plugins[name] - - def get_plugin(self, name, default=None): - return self.plugins.get(name, default) - - -class Plugin(Configurable): - """Base class for IPython plugins.""" - pass diff --git a/IPython/core/tests/test_plugin.py b/IPython/core/tests/test_plugin.py deleted file mode 100644 index 440dba8..0000000 --- a/IPython/core/tests/test_plugin.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Tests for plugin.py""" - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from unittest import TestCase - -from IPython.core.plugin import Plugin, PluginManager - -#----------------------------------------------------------------------------- -# Tests -#----------------------------------------------------------------------------- - -class FooPlugin(Plugin): - pass - - -class BarPlugin(Plugin): - pass - - -class BadPlugin(object): - pass - - -class PluginTest(TestCase): - - def setUp(self): - self.manager = PluginManager() - - def test_register_get(self): - self.assertEqual(None, self.manager.get_plugin('foo')) - foo = FooPlugin() - self.manager.register_plugin('foo', foo) - self.assertEqual(foo, self.manager.get_plugin('foo')) - bar = BarPlugin() - self.assertRaises(KeyError, self.manager.register_plugin, 'foo', bar) - bad = BadPlugin() - self.assertRaises(TypeError, self.manager.register_plugin, 'bad') - - def test_unregister(self): - foo = FooPlugin() - self.manager.register_plugin('foo', foo) - self.manager.unregister_plugin('foo') - self.assertEqual(None, self.manager.get_plugin('foo')) diff --git a/IPython/extensions/autoreload.py b/IPython/extensions/autoreload.py index e024594..27334ed 100644 --- a/IPython/extensions/autoreload.py +++ b/IPython/extensions/autoreload.py @@ -106,13 +106,10 @@ skip_doctest = True #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -import atexit + import imp -import inspect import os import sys -import threading -import time import traceback import types import weakref @@ -409,7 +406,6 @@ def superreload(module, reload=reload, old_objects={}): from IPython.core.hooks import TryNext from IPython.core.magic import Magics, magics_class, line_magic -from IPython.core.plugin import Plugin @magics_class class AutoreloadMagics(Magics): @@ -518,14 +514,6 @@ class AutoreloadMagics(Magics): pass -class AutoreloadPlugin(Plugin): - def __init__(self, shell=None, config=None): - super(AutoreloadPlugin, self).__init__(shell=shell, config=config) - self.auto_magics = AutoreloadMagics(shell) - shell.register_magics(self.auto_magics) - shell.set_hook('pre_run_code_hook', self.auto_magics.pre_run_code_hook) - - _loaded = False @@ -533,6 +521,7 @@ def load_ipython_extension(ip): """Load the extension in IPython.""" global _loaded if not _loaded: - plugin = AutoreloadPlugin(shell=ip, config=ip.config) - ip.plugin_manager.register_plugin('autoreload', plugin) + auto_reload = AutoreloadMagics(ip) + ip.register_magics(auto_reload) + ip.set_hook('pre_run_code_hook', auto_reload.pre_run_code_hook) _loaded = True diff --git a/IPython/extensions/storemagic.py b/IPython/extensions/storemagic.py index 9c9e7c2..b02457b 100644 --- a/IPython/extensions/storemagic.py +++ b/IPython/extensions/storemagic.py @@ -28,9 +28,7 @@ import inspect, os, sys, textwrap from IPython.core.error import UsageError from IPython.core.fakemodule import FakeModule from IPython.core.magic import Magics, magics_class, line_magic -from IPython.core.plugin import Plugin from IPython.testing.skipdoctest import skip_doctest -from IPython.utils.traitlets import Bool, Instance #----------------------------------------------------------------------------- # Functions and classes @@ -211,24 +209,12 @@ class StoreMagics(Magics): print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) -class StoreMagic(Plugin): - shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') - autorestore = Bool(False, config=True) - - def __init__(self, shell, config): - super(StoreMagic, self).__init__(shell=shell, config=config) - shell.register_magics(StoreMagics) - - if self.autorestore: - restore_data(shell) - - _loaded = False + def load_ipython_extension(ip): """Load the extension in IPython.""" global _loaded if not _loaded: - plugin = StoreMagic(shell=ip, config=ip.config) - ip.plugin_manager.register_plugin('storemagic', plugin) + ip.register_magics(StoreMagics) _loaded = True diff --git a/IPython/extensions/tests/test_autoreload.py b/IPython/extensions/tests/test_autoreload.py index 1ac1204..6178171 100644 --- a/IPython/extensions/tests/test_autoreload.py +++ b/IPython/extensions/tests/test_autoreload.py @@ -23,7 +23,7 @@ from StringIO import StringIO import nose.tools as nt import IPython.testing.tools as tt -from IPython.extensions.autoreload import AutoreloadPlugin +from IPython.extensions.autoreload import AutoreloadMagics from IPython.core.hooks import TryNext #----------------------------------------------------------------------------- @@ -35,13 +35,13 @@ noop = lambda *a, **kw: None class FakeShell(object): def __init__(self): self.ns = {} - self.reloader = AutoreloadPlugin(shell=self) + self.auto_magics = AutoreloadMagics(shell=self) register_magics = set_hook = noop def run_code(self, code): try: - self.reloader.auto_magics.pre_run_code_hook(self) + self.auto_magics.pre_run_code_hook(self) except TryNext: pass exec code in self.ns @@ -50,10 +50,10 @@ class FakeShell(object): self.ns.update(items) def magic_autoreload(self, parameter): - self.reloader.auto_magics.autoreload(parameter) + self.auto_magics.autoreload(parameter) def magic_aimport(self, parameter, stream=None): - self.reloader.auto_magics.aimport(parameter, stream=stream) + self.auto_magics.aimport(parameter, stream=stream) class Fixture(object): @@ -72,7 +72,6 @@ class Fixture(object): def tearDown(self): shutil.rmtree(self.test_dir) sys.path = self.old_sys_path - self.shell.reloader.enabled = False self.test_dir = None self.old_sys_path = None diff --git a/docs/source/config/extensions/index.txt b/docs/source/config/extensions/index.txt index f19b31e..808ad43 100644 --- a/docs/source/config/extensions/index.txt +++ b/docs/source/config/extensions/index.txt @@ -43,7 +43,7 @@ functions to load and unload it. Here is a template:: def load_ipython_extension(ipython): # The `ipython` argument is the currently active `InteractiveShell` # instance, which can be used in any way. This allows you to register - # new magics, plugins or aliases, for example. + # new magics or aliases, for example. def unload_ipython_extension(ipython): # If you want your extension to be unloadable, put that logic here. @@ -70,29 +70,6 @@ write extensions, you can also put your extensions in When your extension is ready for general use, please add it to the `extensions index `_. -Plugin class ------------- - -More advanced extensions might want to subclass :class:`IPython.core.plugin.Plugin`. -A plugin can have options configured by IPython's main :ref:`configuration -system `. The code to load and unload it looks like this:: - - def load_ipython_extension(ip): - """Load the plugin in IPython.""" - plugin = MyPlugin(shell=ip, config=ip.config) - try: - ip.plugin_manager.register_plugin('myplugin', plugin) - except KeyError: - print("Already loaded") - - def unload_ipython_extension(ip): - ip.plugin_manager.unregister_plugin('myplugin') - -For examples, see these files: - -* :file:`IPython/extensions/autoreload.py` -* :file:`IPython/extensions/storemagic.py` - .. _bundled_extensions: Extensions bundled with IPython