Vitaly Marin
2008-02-12 07:49:45 UTC
I am trying to generate a python interface to a large code, written in a
mix of Fortran and C, that has source in several sub-directories. I am
interested to wrap most of the top-level subroutines but
need everything else compiled. Since there are a all lot of Fortran
files it is not possible to pass all the information
to compile this code with f2py via the command line.
I have stumbled on a very similar posting at
http://osdir.com/ml/python.f2py.user/2004-01/msg00001.html
My question is how to complete step 4. My code contains multiple large
Makefiles to compile Fortran/C code (for each static library). I have
several static libraries.
How can I let f2py to generate the .so file or files? I would very
much appreciate the help.
More specific example would tremendously help me.
Thank you.
Vitaly
The copy of the posting found that I found
http://osdir.com/ml/python.f2py.user/2004-01/msg00001.html
is Below
1. Build the underlying Fortran libraries in full, as regular static
libs (libfoo.a).
2. Run f2py to generate a .pyf interface automatically. This is only a start.
3. Edit by hand the .pyf from step 2, and remove all references to any
function which is NOT needed from the python side. The python version
only exposes the functions which are specifically needed for the
'outside' world.
3.a [optional] Sometimes you may want to modify a bit how the
functions are exposed to python without messing with the fortran code,
and beyond what .pyf modifications can achieve. In this case, we make
a foo_.so and a foo.py which imports all from foo_.so, and makes the
appropriate changes. This is useful for improving docstrings, for
example, which can't currently be done via f2py.
4. Make a setup.py file which builds foo.so, including libfoo.a as a
library dependency for building foo.so.
This works extremely well for us here. I have a little tool written to
make the setup.py files as compact to write as possible (a few lines),
and a bunch of notes on this which are on the list archives. Email me
if you want the tool or can't find the old notes.
mix of Fortran and C, that has source in several sub-directories. I am
interested to wrap most of the top-level subroutines but
need everything else compiled. Since there are a all lot of Fortran
files it is not possible to pass all the information
to compile this code with f2py via the command line.
I have stumbled on a very similar posting at
http://osdir.com/ml/python.f2py.user/2004-01/msg00001.html
My question is how to complete step 4. My code contains multiple large
Makefiles to compile Fortran/C code (for each static library). I have
several static libraries.
How can I let f2py to generate the .so file or files? I would very
much appreciate the help.
More specific example would tremendously help me.
Thank you.
Vitaly
The copy of the posting found that I found
http://osdir.com/ml/python.f2py.user/2004-01/msg00001.html
is Below
1. Build the underlying Fortran libraries in full, as regular static
libs (libfoo.a).
2. Run f2py to generate a .pyf interface automatically. This is only a start.
3. Edit by hand the .pyf from step 2, and remove all references to any
function which is NOT needed from the python side. The python version
only exposes the functions which are specifically needed for the
'outside' world.
3.a [optional] Sometimes you may want to modify a bit how the
functions are exposed to python without messing with the fortran code,
and beyond what .pyf modifications can achieve. In this case, we make
a foo_.so and a foo.py which imports all from foo_.so, and makes the
appropriate changes. This is useful for improving docstrings, for
example, which can't currently be done via f2py.
4. Make a setup.py file which builds foo.so, including libfoo.a as a
library dependency for building foo.so.
This works extremely well for us here. I have a little tool written to
make the setup.py files as compact to write as possible (a few lines),
and a bunch of notes on this which are on the list archives. Email me
if you want the tool or can't find the old notes.