ipython/ipython — pull request #2538 by rmcgibbo (2012-10-31 19:45:00+00:00)
Title: Enable cell magic functions in .ipy scripts by splitting scripts into multiple cells

Currently, scripts executed from the command line as a single cell, and cell magic functions are only executed if they are at the very start of the cell. This makes it impossible to have code that intersperses regular python code with cell magics inside of .ipy scripts that are executed from the command line, such as:

```
$ cat script.ipy
print "Hello World! (python)"

%%bash
echo "Hello World! (bash)"

print "Hello World! (python)"
```

Which should work like:
```
$ ipython script.ipy
Hello World! (python)
Hello World! (bash)
Hello World! (python)
```

This PR makes this type of code possible, by modifying `IPython.core.InteractiveShell.safe_execfile_ipy()` to split the file into multiple cells before calling `run_cell()`.

I doubt that this patch is really the *right* way to solve this issue, but I hope to just get the conversation started.