Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix %pylab magic.

For a clean solution, added a .registry attribute to magics manager
that will record all magic instances recorded.
  • Loading branch information...
commit dd9ca73c5b47502b52efdedf450bb1b2d78ec060 1 parent f179c85
@fperez authored
Showing with 18 additions and 4 deletions.
  1. +5 −4 IPython/core/interactiveshell.py
  2. +13 −0 IPython/core/magic.py
View
9 IPython/core/interactiveshell.py
@@ -2004,9 +2004,9 @@ def init_magics(self):
self.function_as_magic = self.magics_manager.function_as_magic
self.define_magic = self.magics_manager._define_magic
- self.register_magics(mf.BasicMagics, mf.CodeMagics,
- mf.ConfigMagics, mf.NamespaceMagics, mf.ExecutionMagics,
- mf.AutoMagics, mf.OSMagics, mf.LoggingMagics, mf.ExtensionsMagics,
+ self.register_magics(mf.BasicMagics, mf.CodeMagics, mf.ConfigMagics,
+ mf.ExecutionMagics, mf.NamespaceMagics, mf.AutoMagics,
+ mf.OSMagics, mf.LoggingMagics, mf.ExtensionsMagics,
mf.PylabMagics, mf.DeprecatedMagics)
# FIXME: Move the color initialization to the DisplayHook, which
@@ -2695,7 +2695,8 @@ def enable_pylab(self, gui=None, import_all=True):
# Now we must activate the gui pylab wants to use, and fix %run to take
# plot updates into account
self.enable_gui(gui)
- self._magic.default_runner = mpl_runner(self.safe_execfile)
+ self.magics_manager.registry['ExecutionMagics'].default_runner = \
+ mpl_runner(self.safe_execfile)
#-------------------------------------------------------------------------
# Utilities
View
13 IPython/core/magic.py
@@ -144,8 +144,15 @@ class MagicsManager(Configurable):
"""Object that handles all magic-related functionality for IPython.
"""
# Non-configurable class attributes
+
+ # A two-level dict, first keyed by magic type, then by magic function, and
+ # holding the actual callable object as value. This is the dict used for
+ # magic function dispatch
magics = Dict
+ # A registry of the original objects that we've been given holding magics.
+ registry = Dict
+
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
auto_magic = Bool
@@ -161,6 +168,9 @@ def __init__(self, shell=None, config=None, user_magics=None, **traits):
super(MagicsManager, self).__init__(shell=shell, config=config,
user_magics=user_magics, **traits)
self.magics = dict(line={}, cell={})
+ # Let's add the user_magics to the registry for uniformity, so *all*
+ # registered magic containers can be found there.
+ self.registry[user_magics.__class__.__name__] = user_magics
def auto_status(self):
"""Return descriptive string with automagic status."""
@@ -187,6 +197,9 @@ def register(self, *magic_objects):
# If we're given an uninstantiated class
m = m(self.shell)
+ # Now that we have an instance, we can register it and update the
+ # table of callables
+ self.registry[m.__class__.__name__] = m
for mtype in magic_types:
self.magics[mtype].update(m.magics[mtype])
Please sign in to comment.
Something went wrong with that request. Please try again.