[IPython-dev] Package-specific extensions: an idea

Brian Granger ellisonbg at gmail.com
Fri Jun 17 13:04:55 EDT 2011

On Thu, Jun 16, 2011 at 11:45 PM, Fernando Perez <fperez.net at gmail.com> wrote:
> On Thu, Jun 16, 2011 at 2:16 PM, Robert Kern <robert.kern at gmail.com> wrote:
>> What would the user experience look like in this scenario?
> Since the config file is executed when IPython isn't fully up yet,
> it's not the place to put code that depends on IPython itself, that's
> why we have the exec_files field.  So I have in my config file this:

But wait, extensions are loaded later when IPython has come up fully.
Why not put this logic in the extension itself.  IOW, have the
extension call:


that would fully keep all of the logic localized in the extension as
it should be.


> c.Global.exec_files = ['extras.py']
> and extras.py is a simple python file where I do
> ip = get_ipython()
> and then call whatever I need on that object.  So in this case, you could write:
> ip = get_ipython()
> ip.register_post_execute(yourfunc)
> where yourfunc is defined to be precisely the little blurb of code you
> suggested, that does the deferred module hooking.  yourfunc is any
> callable, so you could have something like
> handler = DeferredHandler()
> ...
> handler.register('numpy', my_numpy_formatter)
> handler.register('traits', my_traits_completer)
> ...
> ip.register_post_execute(handler.execution_hook)
> or whatever method in this object implements the logic you suggested.
> I realize there's a tiny bit more work here, but I think the bulk of
> the boilerplate can be packaged in an easy to use way, and instead of
> adding special-case code to one of the most sensitive codepaths we
> have, we'd be reusing a generic mechanism we have.
> Cheers,
> f
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu and ellisonbg at gmail.com

More information about the IPython-dev mailing list