Show More
@@ -1999,15 +1999,17 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1999 | 1999 | user_magics=mf.UserMagics(self)) |
|
2000 | 2000 | self.configurables.append(self.magics_manager) |
|
2001 | 2001 | |
|
2002 |
self |
|
|
2002 | all_m = [t(self) for t in [mf.BasicMagics, mf.CodeMagics, | |
|
2003 | 2003 | mf.ConfigMagics, mf.NamespaceMagics, mf.ExecutionMagics, |
|
2004 | 2004 | mf.AutoMagics, mf.OSMagics, mf.LoggingMagics, mf.ExtensionsMagics, |
|
2005 |
mf.PylabMagics, mf.DeprecatedMagics |
|
|
2005 | mf.PylabMagics, mf.DeprecatedMagics] ] | |
|
2006 | self.all_m = all_m | |
|
2007 | self.magics_manager.register(*all_m) | |
|
2006 | 2008 | |
|
2007 | 2009 | # FIXME: Move the color initialization to the DisplayHook, which |
|
2008 | 2010 | # should be split into a prompt manager and displayhook. We probably |
|
2009 | 2011 | # even need a centralize colors management object. |
|
2010 | self.magic('colors %s' % self.colors) | |
|
2012 | #self.magic('colors %s' % self.colors) | |
|
2011 | 2013 | # History was moved to a separate module |
|
2012 | 2014 | from IPython.core import history |
|
2013 | 2015 | history.init_ipython(self) |
@@ -110,20 +110,18 b' def _magic_marker(magic_type):' | |||
|
110 | 110 | name = func.func_name |
|
111 | 111 | func.magic_name = name |
|
112 | 112 | retval = decorator(call, func) |
|
113 | magics[magic_type][name] = name | |
|
113 | 114 | elif isinstance(arg, basestring): |
|
114 | 115 | # Decorator called with arguments (@foo('bar')) |
|
115 | 116 | name = arg |
|
116 | 117 | def mark(func, *a, **kw): |
|
117 | 118 | func.magic_name = name |
|
119 | magics[magic_type][name] = func.func_name | |
|
118 | 120 | return decorator(call, func) |
|
119 | 121 | retval = mark |
|
120 | 122 | else: |
|
121 | 123 | raise ValueError("Decorator can only be called with " |
|
122 | 124 | "string or function") |
|
123 | # Record the magic function in the global table that will then be | |
|
124 | # appended to the class via the register_magics class decorator | |
|
125 | #print 'magics:', magics # dbg | |
|
126 | magics[magic_type][name] = retval | |
|
127 | 125 | |
|
128 | 126 | return retval |
|
129 | 127 | |
@@ -157,6 +155,7 b' class MagicsManager(Configurable):' | |||
|
157 | 155 | |
|
158 | 156 | super(MagicsManager, self).__init__(shell=shell, config=config, |
|
159 | 157 | user_magics=user_magics, **traits) |
|
158 | self.magics = dict(line={}, cell={}) | |
|
160 | 159 | |
|
161 | 160 | def auto_status(self): |
|
162 | 161 | """Return descriptive string with automagic status.""" |
@@ -170,20 +169,17 b' class MagicsManager(Configurable):' | |||
|
170 | 169 | """ |
|
171 | 170 | return self.magics |
|
172 | 171 | |
|
173 | def register(self, *magics): | |
|
172 | def register(self, *magic_objects): | |
|
174 | 173 | """Register one or more instances of Magics. |
|
175 | 174 | """ |
|
176 | 175 | # Start by validating them to ensure they have all had their magic |
|
177 | 176 | # methods registered at the instance level |
|
178 | for m in magics: | |
|
177 | for m in magic_objects: | |
|
179 | 178 | if not m.registered: |
|
180 | 179 | raise ValueError("Class of magics %r was constructed without " |
|
181 | 180 | "the @register_macics class decorator") |
|
182 |
|
|
|
183 | # If we're given an uninstantiated class | |
|
184 | m = m(self.shell) | |
|
185 | ||
|
186 | self.magics.update(m.magics) | |
|
181 | for mtype in magic_types: | |
|
182 | self.magics[mtype].update(m.magics[mtype]) | |
|
187 | 183 | |
|
188 | 184 | def define_magic(self, magic_name, func, magic_type='line'): |
|
189 | 185 | """Expose own function as magic function for ipython |
@@ -241,6 +237,12 b' class Magics(object):' | |||
|
241 | 237 | if not(self.__class__.registered): |
|
242 | 238 | raise ValueError('unregistered Magics') |
|
243 | 239 | self.shell = shell |
|
240 | mtab = dict(line={}, cell={}) | |
|
241 | for mtype in magic_types: | |
|
242 | tab = mtab[mtype] | |
|
243 | for magic_name, meth_name in self.magics[mtype].iteritems(): | |
|
244 | tab[magic_name] = getattr(self, meth_name) | |
|
245 | self.magics.update(mtab) | |
|
244 | 246 | |
|
245 | 247 | def arg_err(self,func): |
|
246 | 248 | """Print docstring if incorrect arguments were passed""" |
General Comments 0
You need to be logged in to leave comments.
Login now