[IPython-User] Fortran cell magic

Matthias BUSSONNIER bussonniermatthias@gmail....
Wed Sep 11 06:55:01 CDT 2013

Le 11 sept. 2013 à 00:54, Martín Gaitán a écrit :

> On Tue, Sep 10, 2013 at 4:19 AM, Matthias BUSSONNIER <bussonniermatthias@gmail.com> wrote:
> For mosts things that would be a single line to add/ monkey patch: 
> https://github.com/ipython/ipython/blob/master/IPython/html/static/notebook/js/config.js#L57
> ,'magic_fortran'      :{'reg':[/^%%fortran/]}
> Unfortunately, it seem code mirror does not support fortran (yet)
> I've sent a pull request  with a basic Fortran mode 
> https://github.com/marijnh/CodeMirror/pull/1815
> I hope it will be accepted soon, but then... I should wait for a repack of ipython's components, right?

Has already been accepted apparently.
It is possible to "backport" on earlier IPython by tweaking the profile.
I'll see If I can come up with a PR agains your repo that does it. 

Or if you are interested, you can just inject the file you have in above PR in IPython using custom.js
and it should almost work out of the box.

> Well living in the same repo might not always make sense, but in case like %%R/rpy2 %%cython/cython, the magic is just a higher level wrapper to API. 
> So it might make sense to have it together.  I don't really use fortran (anymore) so I'm not in a good place to judge, this was jus t a proposition. 
> I might have.
> From a end user point of view, you have either the : 
>  - to use fortran with python, the best is IPython with fortran magic.
>  - you have to  install fortran magic.
>  - but fortran magic use f2py 
>  - once done if you have the correct f2py version installed it works
> or
>  - to use fortran with python : install f2py
>  - oh, and by the way if you are using ipython you can "Just" do load ext numpy.f2py and you have a fortran magic.
> it feels for me exactly the same as %sympyprinting and panda html dataframe option.
> they are part of the package, and if you are using IPython you "just" have to enable them.
> (I guess a package can even try to detect if it is in IPython at import time and register magic automagically
> even if explicit is better than implicit.)
> I got the point, but doesn't be a better idea to do this "registration" automatically in the external package install process? I mean, if I have ipython installed and I install numpy/f2py, then numpy automatically should register its "magic for ipython". Once it's already installed, I could directly use "%%fortran" in a cell without importing anything.

I do not agree with that, you can imagine have different implementation of the same magic. So if 2 external packages define the rmagic 
How would you decide which one to use ? 

Also having code of some magics to work might require loading library you don't want. As it might take a lot of time to load. 

But I would expect if possible that doing 

import numpy.f2py as f2py

make the magic available in current namespace would be nice, but again it does something that might be "unexpected"
for some user. 

> I guess this could be done more or less easily declaring setuptool's "entry points" in the ipython's setup.py.
> http://pythonhosted.org/distribute/setuptools.html#dynamic-discovery-of-services-and-plugins
> For example, this is the architecture used in the nose's plugin machinery:
> http://nose.readthedocs.org/en/latest/plugins/writing.html#registering 
> let me know if it sounds like a good idea

having a way to know which magic might be available would be a good thing though.

> cheers. 
> martin
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20130911/0d64ced3/attachment.html 

More information about the IPython-User mailing list