[IPython-dev] Towards IPython 1.0, the famous big cleanup
Fernando Perez
Fernando.Perez at colorado.edu
Fri Apr 15 14:27:31 EDT 2005
Ville Vainio wrote:
> On Thu, 2005-04-14 at 17:19 -0600, Fernando Perez wrote:
>
>
>>- the magic system will be fully overhauled. The core of your custom magics
>>will most likely run unchanged, but how they plug into ipython will change.
>
>
> I've probably said this before, but -
>
> Do we need a magic system at all?
>
> It would be cleaner if what are now "magic" would be just normal Python
> functions/callables, with some additional metadata about how it wants to
> receive the argument string. To behave exactly like magics (apart from
> separate namespace and %), it would just need to take a single string
> (the whole command line) as argument.
Well, that's pretty much what they do today. It's just that making a new
magic involves binding by hand an instance method with a special name, for
example:
from IPython.iplib import InteractiveShell
def magic_runbatch(self, parameter_s=''):
""" runbatch magic command.
"""
try:
fileobj = open(parameter_s,'r')
except:
print "Error: could not open file",parameter_s
return
else:
self.shell.runlines(fileobj.read())
InteractiveShell.magic_runbatch = magic_runbatch
del magic_runbatch
What I envision, is something cleaner, more like:
__IPYTHON__.set_new_magic(your_function,optional_name='mymagic',opt_args=...)
And that's it. Any function you write can be made into a magic, as long as it
conforms to a minimal API. When I actually start working on this (probably
item #2 after the config system rewrite), I'll make sure to post my plan to
this list, so anyone with thoughts/criticisms can voice them early on before I
spend too much time coding myself into a silly corner.
> Shell commands would all refer to the same object, one that takes the
> whole command line and does the deed.
Again, today we pretty much have this already, it's just not cleanly indicated
and documented.
But thanks for the comments: I _really_ want people to voice any and all
concerns or ideas they may have in this direction. I hope that when 1.0 comes
out, we can be reasonably happy that the publicly exposed API is stable enough
that users can rely on it for a while. So by all means, speak up!
Best,
f
More information about the IPython-dev
mailing list