diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e73c9bb..cd1cb81 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1999,15 +1999,17 @@ class InteractiveShell(SingletonConfigurable): user_magics=mf.UserMagics(self)) self.configurables.append(self.magics_manager) - self.magics_manager.register(mf.BasicMagics, mf.CodeMagics, + all_m = [t(self) for t in [mf.BasicMagics, mf.CodeMagics, mf.ConfigMagics, mf.NamespaceMagics, mf.ExecutionMagics, mf.AutoMagics, mf.OSMagics, mf.LoggingMagics, mf.ExtensionsMagics, - mf.PylabMagics, mf.DeprecatedMagics) + mf.PylabMagics, mf.DeprecatedMagics] ] + self.all_m = all_m + self.magics_manager.register(*all_m) # FIXME: Move the color initialization to the DisplayHook, which # should be split into a prompt manager and displayhook. We probably # even need a centralize colors management object. - self.magic('colors %s' % self.colors) + #self.magic('colors %s' % self.colors) # History was moved to a separate module from IPython.core import history history.init_ipython(self) diff --git a/IPython/core/magic.py b/IPython/core/magic.py index b031e27..6a6cbca 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -110,20 +110,18 @@ def _magic_marker(magic_type): name = func.func_name func.magic_name = name retval = decorator(call, func) + magics[magic_type][name] = name elif isinstance(arg, basestring): # Decorator called with arguments (@foo('bar')) name = arg def mark(func, *a, **kw): func.magic_name = name + magics[magic_type][name] = func.func_name return decorator(call, func) retval = mark else: raise ValueError("Decorator can only be called with " "string or function") - # Record the magic function in the global table that will then be - # appended to the class via the register_magics class decorator - #print 'magics:', magics # dbg - magics[magic_type][name] = retval return retval @@ -157,6 +155,7 @@ class MagicsManager(Configurable): super(MagicsManager, self).__init__(shell=shell, config=config, user_magics=user_magics, **traits) + self.magics = dict(line={}, cell={}) def auto_status(self): """Return descriptive string with automagic status.""" @@ -170,20 +169,17 @@ class MagicsManager(Configurable): """ return self.magics - def register(self, *magics): + def register(self, *magic_objects): """Register one or more instances of Magics. """ # Start by validating them to ensure they have all had their magic # methods registered at the instance level - for m in magics: + for m in magic_objects: if not m.registered: raise ValueError("Class of magics %r was constructed without " "the @register_macics class decorator") - if type(m) is type: - # If we're given an uninstantiated class - m = m(self.shell) - - self.magics.update(m.magics) + for mtype in magic_types: + self.magics[mtype].update(m.magics[mtype]) def define_magic(self, magic_name, func, magic_type='line'): """Expose own function as magic function for ipython @@ -241,6 +237,12 @@ class Magics(object): if not(self.__class__.registered): raise ValueError('unregistered Magics') self.shell = shell + mtab = dict(line={}, cell={}) + for mtype in magic_types: + tab = mtab[mtype] + for magic_name, meth_name in self.magics[mtype].iteritems(): + tab[magic_name] = getattr(self, meth_name) + self.magics.update(mtab) def arg_err(self,func): """Print docstring if incorrect arguments were passed""" diff --git a/IPython/core/magic_functions.py b/IPython/core/magic_functions.py index e8f3e24..f00be7f 100644 --- a/IPython/core/magic_functions.py +++ b/IPython/core/magic_functions.py @@ -241,7 +241,6 @@ Currently the magic system has the following functions:""", %colors nocolor """ - def color_switch_err(name): warn('Error changing %s color schemes.\n%s' % (name,sys.exc_info()[1]))