##// END OF EJS Templates
Restore autorestore option for storemagic....
Thomas Kluyver -
Show More
@@ -25,10 +25,12 b' To automatically restore stored variables at startup, add this to your'
25 25 import inspect, os, sys, textwrap
26 26
27 27 # Our own
28 from IPython.config.configurable import Configurable
28 29 from IPython.core.error import UsageError
29 30 from IPython.core.fakemodule import FakeModule
30 31 from IPython.core.magic import Magics, magics_class, line_magic
31 32 from IPython.testing.skipdoctest import skip_doctest
33 from IPython.utils.traitlets import Bool
32 34
33 35 #-----------------------------------------------------------------------------
34 36 # Functions and classes
@@ -68,11 +70,24 b' def restore_data(ip):'
68 70
69 71
70 72 @magics_class
71 class StoreMagics(Magics):
73 class StoreMagics(Magics, Configurable):
72 74 """Lightweight persistence for python variables.
73 75
74 76 Provides the %store magic."""
75 77
78 autorestore = Bool(False, config=True, help=
79 """If True, any %store-d variables will be automatically restored
80 when IPython starts.
81 """
82 )
83
84 def __init__(self, shell):
85 Configurable.__init__(self, config=shell.config)
86 Magics.__init__(self, shell=shell)
87 self.shell.configurables.append(self)
88 if self.autorestore:
89 restore_data(self.shell)
90
76 91 @skip_doctest
77 92 @line_magic
78 93 def store(self, parameter_s=''):
@@ -225,3 +240,4 b' class StoreMagics(Magics):'
225 240 def load_ipython_extension(ip):
226 241 """Load the extension in IPython."""
227 242 ip.register_magics(StoreMagics)
243
@@ -47,6 +47,7 b' from IPython.core.magics import ScriptMagics'
47 47 from IPython.core.shellapp import (
48 48 InteractiveShellApp, shell_flags, shell_aliases
49 49 )
50 from IPython.extensions.storemagic import StoreMagics
50 51 from IPython.terminal.interactiveshell import TerminalInteractiveShell
51 52 from IPython.utils import warn
52 53 from IPython.utils.path import get_ipython_dir, check_for_old_config
@@ -219,6 +220,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
219 220 PlainTextFormatter,
220 221 IPCompleter,
221 222 ScriptMagics,
223 StoreMagics,
222 224 ]
223 225
224 226 subcommands = Dict(dict(
General Comments 0
You need to be logged in to leave comments. Login now