Repository: ipython/ipython

Issue:
StoreMagic.autorestore not working in 1.0.0
Since upgrading Ipython to version 1.0.0, the variables I have in `%store` don't seem to be loaded on startup, and have to be refreshed manually using `%store -r`.

My `ipython_config.py` file contains the line:

```
c.StoreMagic.autorestore = True
```

but this doesn't seem to have any effect.

My version info is:

```
{'codename': 'An Afternoon Hack',
 'commit_hash': '02da31c',
 'commit_source': 'installation',
  'default_encoding': 'cp1252',
  'ipython_path': 'C:\\Anaconda\\lib\\site-packages\\IPython',
  'ipython_version': '1.0.0',
  'os_name': 'nt',
  'platform': 'Windows-7-6.1.7601-SP1',
  'sys_executable': 'C:\\Anaconda\\pythonw.exe',
  'sys_platform': 'win32',
  'sys_version': '2.7.5 |Anaconda 1.6.2 (32-bit)| (default, Jul  1 2013, 12:41:55) [MSC v.1500 32 bit (Intel)]'}
```



Discussion:
It appears that when the 'plugin' architecture was removed in 1e6eb00cc9dd5f4550ba4b47042794f6a8c717ce, this setting was dropped entirely. That presumably wasn't intended.


Resolving patch:
diff --git a/IPython/extensions/storemagic.py b/IPython/extensions/storemagic.py
--- a/IPython/extensions/storemagic.py
+++ b/IPython/extensions/storemagic.py
@@ -25,10 +25,12 @@
 import inspect, os, sys, textwrap
 
 # Our own
+from IPython.config.configurable import Configurable
 from IPython.core.error import UsageError
 from IPython.core.fakemodule import FakeModule
 from IPython.core.magic import Magics, magics_class, line_magic
 from IPython.testing.skipdoctest import skip_doctest
+from IPython.utils.traitlets import Bool
 
 #-----------------------------------------------------------------------------
 # Functions and classes
@@ -68,10 +70,23 @@ def restore_data(ip):
 
 
 @magics_class
-class StoreMagics(Magics):
+class StoreMagics(Magics, Configurable):
     """Lightweight persistence for python variables.
 
     Provides the %store magic."""
+    
+    autorestore = Bool(False, config=True, help=
+        """If True, any %store-d variables will be automatically restored
+        when IPython starts.
+        """
+    )
+    
+    def __init__(self, shell):
+        Configurable.__init__(self, config=shell.config)
+        Magics.__init__(self, shell=shell)
+        self.shell.configurables.append(self)
+        if self.autorestore:
+            restore_data(self.shell)
 
     @skip_doctest
     @line_magic
@@ -225,3 +240,4 @@ def store(self, parameter_s=''):
 def load_ipython_extension(ip):
     """Load the extension in IPython."""
     ip.register_magics(StoreMagics)
+    
diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py
--- a/IPython/terminal/ipapp.py
+++ b/IPython/terminal/ipapp.py
@@ -47,6 +47,7 @@
 from IPython.core.shellapp import (
     InteractiveShellApp, shell_flags, shell_aliases
 )
+from IPython.extensions.storemagic import StoreMagics
 from IPython.terminal.interactiveshell import TerminalInteractiveShell
 from IPython.utils import warn
 from IPython.utils.path import get_ipython_dir, check_for_old_config
@@ -219,6 +220,7 @@ def _classes_default(self):
             PlainTextFormatter,
             IPCompleter,
             ScriptMagics,
+            StoreMagics,
         ]
 
     subcommands = Dict(dict(


Test patch:
diff --git a/IPython/extensions/tests/test_storemagic.py b/IPython/extensions/tests/test_storemagic.py
--- a/IPython/extensions/tests/test_storemagic.py
+++ b/IPython/extensions/tests/test_storemagic.py
@@ -1,5 +1,6 @@
 import tempfile, os
 
+from IPython.config.loader import Config
 import nose.tools as nt
 
 ip = get_ipython()
@@ -30,3 +31,20 @@ def test_store_restore():
     nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
     
     os.rmdir(tmpd)
+
+def test_autorestore():
+    ip.user_ns['foo'] = 95
+    ip.magic('store foo')
+    del ip.user_ns['foo']
+    c = Config()
+    c.StoreMagics.autorestore = False
+    orig_config = ip.config
+    try:
+        ip.config = c
+        ip.extension_manager.reload_extension('storemagic')
+        nt.assert_not_in('foo', ip.user_ns)
+        c.StoreMagics.autorestore = True
+        ip.extension_manager.reload_extension('storemagic')
+        nt.assert_equal(ip.user_ns['foo'], 95)
+    finally:
+        ip.config = orig_config