F2PY and build systems
In this section we will cover the various popular build systems and their usage
with f2py.
In this section we will cover the various popular build systems and their usage
with f2py.
mesonAll changes to
f2pyare tested on SciPy, so their CI configuration is always supported.
Building an extension module which includes Python and Fortran consists of:
Fortran source(s)
One or more generated files from f2py
A C wrapper file is always created
Code with modules require an additional .f90 wrapper
Code with functions generate an additional .f wrapper
fortranobject.{c,h}
Distributed with numpy
Can be queried via python -c "import numpy.f2py; print(numpy.f2py.get_include())"
NumPy headers
Can be queried via python -c "import numpy; print(numpy.get_include())"
Python libraries and development headers
Broadly speaking there are three cases which arise when considering the outputs of f2py:
Input file blah.f
Generates
blahmodule.c
blah-f2pywrappers.f
When no COMMON blocks are present only a C wrapper file is generated.
Wrappers are also generated to rewrite assumed shape arrays as automatic
arrays.
Input file blah.f90
Generates:
In theory keeping the above requirements in hand, any build system can be
adapted to generate f2py extension modules. Here we will cover a subset of
the more popular systems.
blah-f2pywrappers.f
blah-f2pywrappers2.f90
The f90 wrapper is used to handle code which is subdivided into
modules. The f wrapper makes subroutines for functions. It
rewrites assumed shape arrays as automatic arrays.
Input file blah.pyf
Generates:
blahmodule.c
blah-f2pywrappers2.f90 (occasionally)
blah-f2pywrappers.f (occasionally)
Signature files .pyf do not signal their language standard via the file
extension, they may generate the F90 and F77 specific wrappers depending on
their contents; which shifts the burden of checking for generated files onto
the build system.