[IPython-dev] Static code analysis of IPython Notebook cell

Thomas Kluyver takowl at gmail.com
Mon Jul 7 09:47:13 EDT 2014


On 7 July 2014 00:20, Thomas Wiecki <thomas.wiecki at gmail.com> wrote:

> With my limited understanding of the IPyNB internals I would see three
> ways this could be achieved:
> * There is a hook in the IPyNB I can use like the magic
> * I have to change the IPyNB client code to do the analysis before it's
> sent to the kernel.
> * I change the kernel to do the analysis.
>
> Which of these is the best? Can someone point me to the relevant code
> section I would need to make changes to?


I think you can make use of the hooks already in the kernel. If you're just
checking the AST, it's fairly straightforward: just register an AST
transformer as described here:
http://ipython.org/ipython-doc/dev/config/inputtransforms.html#ast-transformations
. It doesn't need to do any transformations: you can simply inspect the
code and return it unchanged. Or you can replace it all with Pass() to
prevent the cell from executing. It would still look as if it had executed
from the frontend, though.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140707/33d7a45b/attachment.html>


More information about the IPython-dev mailing list