bundles / numpy 2.4.4 / docs
Doc
F2PY and build systems
docs/f2py:buildtools:index
In this section we will cover the various popular build systems and their usage with f2py.
Basic concepts
Building an extension module which includes Python and Fortran consists of:
Fortran source(s)
One or more generated files from
f2pyA
Cwrapper file is always createdCode with modules require an additional
.f90wrapperCode with functions generate an additional
.fwrapper
fortranobject.{c,h}Distributed with
numpyCan 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:
Fortran 77 programs
Input file
blah.fGenerates
blahmodule.cblah-f2pywrappers.f
When no
COMMONblocks are present only aCwrapper file is generated. Wrappers are also generated to rewrite assumed shape arrays as automatic arrays.Fortran 90 programs
Input file
blah.f90Generates:
blahmodule.cblah-f2pywrappers.fblah-f2pywrappers2.f90
The
f90wrapper is used to handle code which is subdivided into modules. Thefwrapper makessubroutinesforfunctions. It rewrites assumed shape arrays as automatic arrays.Signature files
Input file
blah.pyfGenerates:
blahmodule.cblah-f2pywrappers2.f90(occasionally)blah-f2pywrappers.f(occasionally)
Signature files
.pyfdo 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.
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.