Show More
@@ -130,6 +130,9 b' class InteractiveShellApp(Configurable):' | |||||
130 | if new: |
|
130 | if new: | |
131 | # add to self.extensions |
|
131 | # add to self.extensions | |
132 | self.extensions.append(new) |
|
132 | self.extensions.append(new) | |
|
133 | ||||
|
134 | # Extensions that are always loaded (not configurable) | |||
|
135 | default_extensions = List(Unicode, [u'storemagic'], config=False) | |||
133 |
|
136 | |||
134 | exec_files = List(Unicode, config=True, |
|
137 | exec_files = List(Unicode, config=True, | |
135 | help="""List of files to run at IPython startup.""" |
|
138 | help="""List of files to run at IPython startup.""" | |
@@ -158,11 +161,9 b' class InteractiveShellApp(Configurable):' | |||||
158 | This uses the :meth:`ExtensionManager.load_extensions` to load all |
|
161 | This uses the :meth:`ExtensionManager.load_extensions` to load all | |
159 | the extensions listed in ``self.extensions``. |
|
162 | the extensions listed in ``self.extensions``. | |
160 | """ |
|
163 | """ | |
161 | if not self.extensions: |
|
|||
162 | return |
|
|||
163 | try: |
|
164 | try: | |
164 | self.log.debug("Loading IPython extensions...") |
|
165 | self.log.debug("Loading IPython extensions...") | |
165 | extensions = self.extensions |
|
166 | extensions = self.default_extensions + self.extensions | |
166 | for ext in extensions: |
|
167 | for ext in extensions: | |
167 | try: |
|
168 | try: | |
168 | self.log.info("Loading IPython extension: %s" % ext) |
|
169 | self.log.info("Loading IPython extension: %s" % ext) |
@@ -2,26 +2,24 b'' | |||||
2 | """ |
|
2 | """ | |
3 | %store magic for lightweight persistence. |
|
3 | %store magic for lightweight persistence. | |
4 |
|
4 | |||
5 |
Stores variables, aliases and macros in IPython's database. |
|
5 | Stores variables, aliases and macros in IPython's database. | |
6 | be automatically restored whenever the extension is loaded. |
|
|||
7 |
|
6 | |||
8 | To enable this functionality, list it in your default profile |
|
7 | To automatically restore stored variables at startup, add this to your | |
9 | `ipython_config.py` file:: |
|
8 | :file:`ipython_config.py` file:: | |
10 |
|
9 | |||
11 | c.InteractiveShellApp.extensions = ['storemagic'] |
|
10 | c.StoreMagic.autorestore = True | |
12 |
|
||||
13 | Or to use it temporarily, run this in your IPython session:: |
|
|||
14 |
|
||||
15 | %load_ext storemagic |
|
|||
16 |
|
11 | |||
17 | """ |
|
12 | """ | |
18 |
|
13 | |||
19 | from IPython.core.error import TryNext, UsageError |
|
14 | from IPython.core.error import TryNext, UsageError | |
|
15 | from IPython.core.plugin import Plugin | |||
|
16 | from IPython.testing.skipdoctest import skip_doctest | |||
20 | from IPython.utils import pickleshare |
|
17 | from IPython.utils import pickleshare | |
|
18 | from IPython.utils.traitlets import Bool, Instance | |||
21 |
|
19 | |||
22 | import inspect,pickle,os,sys,textwrap |
|
20 | import inspect,pickle,os,sys,textwrap | |
23 | from IPython.core.fakemodule import FakeModule |
|
21 | from IPython.core.fakemodule import FakeModule | |
24 |
|
22 | |||
25 | def restore_aliases(ip): |
|
23 | def restore_aliases(ip): | |
26 | staliases = ip.db.get('stored_aliases', {}) |
|
24 | staliases = ip.db.get('stored_aliases', {}) | |
27 | for k,v in staliases.items(): |
|
25 | for k,v in staliases.items(): | |
@@ -53,6 +51,7 b' def restore_data(ip):' | |||||
53 | restore_aliases(ip) |
|
51 | restore_aliases(ip) | |
54 | restore_dhist(ip) |
|
52 | restore_dhist(ip) | |
55 |
|
53 | |||
|
54 | @skip_doctest | |||
56 | def magic_store(self, parameter_s=''): |
|
55 | def magic_store(self, parameter_s=''): | |
57 | """Lightweight persistence for python variables. |
|
56 | """Lightweight persistence for python variables. | |
58 |
|
57 | |||
@@ -183,6 +182,24 b" def magic_store(self, parameter_s=''):" | |||||
183 | self.db[ 'autorestore/' + args[0] ] = obj |
|
182 | self.db[ 'autorestore/' + args[0] ] = obj | |
184 | print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) |
|
183 | print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) | |
185 |
|
184 | |||
|
185 | ||||
|
186 | class StoreMagic(Plugin): | |||
|
187 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |||
|
188 | autorestore = Bool(False, config=True) | |||
|
189 | ||||
|
190 | def __init__(self, shell, config): | |||
|
191 | super(StoreMagic, self).__init__(shell=shell, config=config) | |||
|
192 | shell.define_magic('store', magic_store) | |||
|
193 | ||||
|
194 | if self.autorestore: | |||
|
195 | restore_data(shell) | |||
|
196 | ||||
|
197 | _loaded = False | |||
|
198 | ||||
186 | def load_ipython_extension(ip): |
|
199 | def load_ipython_extension(ip): | |
187 | ip.define_magic('store', magic_store) |
|
200 | """Load the extension in IPython.""" | |
188 | restore_data(ip) |
|
201 | global _loaded | |
|
202 | if not _loaded: | |||
|
203 | plugin = StoreMagic(shell=ip, config=ip.config) | |||
|
204 | ip.plugin_manager.register_plugin('storemagic', plugin) | |||
|
205 | _loaded = True |
@@ -62,8 +62,9 b' New features' | |||||
62 | Terminal frontend by default (:ghpull:`838`). |
|
62 | Terminal frontend by default (:ghpull:`838`). | |
63 |
|
63 | |||
64 | * **%store**: The ``%store`` magic from earlier versions has been updated and |
|
64 | * **%store**: The ``%store`` magic from earlier versions has been updated and | |
65 | placed in an extension, :ref:`extensions_storemagic`. Add 'storemagic' to ``c.InteractiveShellApp.extensions`` |
|
65 | re-enabled (:ref:`extensions_storemagic`; :ghpull:`1029`). To autorestore | |
66 | in ipython_config.py to enable it (:ghpull:`1029`). |
|
66 | stored variables on startup, specify ``c.StoreMagic.autorestore = True`` in | |
|
67 | :file:`ipython_config.py`. | |||
67 |
|
68 | |||
68 |
|
69 | |||
69 |
|
70 |
General Comments 0
You need to be logged in to leave comments.
Login now