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