##// 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 import inspect, os, sys, textwrap
25 import inspect, os, sys, textwrap
26
26
27 # Our own
27 # Our own
28 from IPython.config.configurable import Configurable
28 from IPython.core.error import UsageError
29 from IPython.core.error import UsageError
29 from IPython.core.fakemodule import FakeModule
30 from IPython.core.fakemodule import FakeModule
30 from IPython.core.magic import Magics, magics_class, line_magic
31 from IPython.core.magic import Magics, magics_class, line_magic
31 from IPython.testing.skipdoctest import skip_doctest
32 from IPython.testing.skipdoctest import skip_doctest
33 from IPython.utils.traitlets import Bool
32
34
33 #-----------------------------------------------------------------------------
35 #-----------------------------------------------------------------------------
34 # Functions and classes
36 # Functions and classes
@@ -68,10 +70,23 b' def restore_data(ip):'
68
70
69
71
70 @magics_class
72 @magics_class
71 class StoreMagics(Magics):
73 class StoreMagics(Magics, Configurable):
72 """Lightweight persistence for python variables.
74 """Lightweight persistence for python variables.
73
75
74 Provides the %store magic."""
76 Provides the %store magic."""
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)
75
90
76 @skip_doctest
91 @skip_doctest
77 @line_magic
92 @line_magic
@@ -225,3 +240,4 b' class StoreMagics(Magics):'
225 def load_ipython_extension(ip):
240 def load_ipython_extension(ip):
226 """Load the extension in IPython."""
241 """Load the extension in IPython."""
227 ip.register_magics(StoreMagics)
242 ip.register_magics(StoreMagics)
243
@@ -47,6 +47,7 b' from IPython.core.magics import ScriptMagics'
47 from IPython.core.shellapp import (
47 from IPython.core.shellapp import (
48 InteractiveShellApp, shell_flags, shell_aliases
48 InteractiveShellApp, shell_flags, shell_aliases
49 )
49 )
50 from IPython.extensions.storemagic import StoreMagics
50 from IPython.terminal.interactiveshell import TerminalInteractiveShell
51 from IPython.terminal.interactiveshell import TerminalInteractiveShell
51 from IPython.utils import warn
52 from IPython.utils import warn
52 from IPython.utils.path import get_ipython_dir, check_for_old_config
53 from IPython.utils.path import get_ipython_dir, check_for_old_config
@@ -219,6 +220,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
219 PlainTextFormatter,
220 PlainTextFormatter,
220 IPCompleter,
221 IPCompleter,
221 ScriptMagics,
222 ScriptMagics,
223 StoreMagics,
222 ]
224 ]
223
225
224 subcommands = Dict(dict(
226 subcommands = Dict(dict(
General Comments 0
You need to be logged in to leave comments. Login now