[IPython-dev] possible feature request: auto-run

Fernando Perez fperez at colorado.edu
Tue Apr 29 17:41:40 EDT 2003


Kasper Souren wrote:
> Hi!
> 
> I just had a little idea for a new IPython feature. I don't know if it's 
> feasible, but it seems quite useful: auto-run .py files.
> 
> Suppose you are editing a .py file (say test.py) and you're also working in 
> ipython to check out the changes you made. Currently you need to do a "run 
> test" every time you changed something. Now instead of doing the run 
> yourself, IPython could look out for changes in certain files (like test.py) 
> and rerun those files for you.
> 
> Of course there is at least one big problem with this: what to do if the file 
> causes some errors.
> 
> So now I'm interested in your reactions. :)

Well, I don't see this going in.  The effort/benefit ratio is really quite 
poor, IMHO.  For this to work, you'd need to set up a magic function which 
handles a table of registered functions to watch for changes, and poll them 
periodically.  Since you don't want to interfere with the rest of ipython, 
you'll need to make it live in its own thread, or put it into a hook somewhere 
which gets executed at fixed events (more on this later).

It's rather complicated to get it right, and considering that python gives you 
macros, it seems pointless:

In [1]: run test.py
foo

In [2]: macro x 1
Macro `x` created. To execute, type its name (without quotes).
Macro contents:
__IP.magic_run ("test.py")

In [3]: x
Out[3]: Executing Macro...
foo

*** file test was changed here

In [4]: x
Out[4]: Executing Macro...
bar

So you can make this a one-letter operation trivially.  Considering that you 
can also:

- edit your files using @edit, which automatically executes them,

- run ipython within emacs, which gives you a single key acess to executing a 
file,

it seems like we already have this problem fairly well solved.

But if you _really_ insist, feel free to add to your _prefilter function 
something which checks for changes in files and runs them.  See the tutorial 
profile example for details.  This way would be fairly easy to implement and 
you can keep it active in your default profile.

I don't want this in the mainline code for now because if it goes in, I have 
to maintain it :)  But feel free to write your own with _prefilter and test it 
for a while.  If it works well, we can put it in the public wiki contributions 
area (said wiki doesn't exist yet, but we can create one for users to share 
ipython snippets easily).

Sorry to discourage you, but an architectural overhaul of ipython is just a 
much more important use of my very limited resources right now.

Best,

Fernando.




More information about the IPython-dev mailing list