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

Fernando Perez fperez.net@gmail....
Fri Jun 17 01:45:33 CDT 2011


On Thu, Jun 16, 2011 at 2:16 PM, Robert Kern <robert.kern@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:

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


More information about the IPython-dev mailing list