diff --git a/IPython/extensions/storemagic.py b/IPython/extensions/storemagic.py index 92f94c9..19282f8 100644 --- a/IPython/extensions/storemagic.py +++ b/IPython/extensions/storemagic.py @@ -17,11 +17,13 @@ Or to use it temporarily, run this in your IPython session:: """ from IPython.core.error import TryNext, UsageError +from IPython.core.plugin import Plugin from IPython.utils import pickleshare +from IPython.utils.traitlets import Bool, Instance import inspect,pickle,os,sys,textwrap from IPython.core.fakemodule import FakeModule - + def restore_aliases(ip): staliases = ip.db.get('stored_aliases', {}) for k,v in staliases.items(): @@ -183,6 +185,24 @@ def magic_store(self, parameter_s=''): self.db[ 'autorestore/' + args[0] ] = obj 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.define_magic('store', magic_store) + + if self.autorestore: + restore_data(shell) + +_loaded = False + def load_ipython_extension(ip): - ip.define_magic('store', magic_store) - restore_data(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) + _loaded = True