Automatic extension module generation

If you want to distribute your f2py extension module, then you only need to include the .pyf file and the Fortran code. The distutils extensions in NumPy allow you to define an extension module entirely in terms of this interface file. A valid setup.py file allowing distribution of the add.f module (as part of the package f2py.examples so that it would be loaded as f2py.examples.add) is def configuration (parent_package='' , top_path=None)

from numpy.distutils.misc_util import Configuration config = Configuration ('f2py_examples',parent-package, top_path) conf ig. add_extension (' add' , sources= [' add .pyf' , ' add. f' ] ) return config if __name__ == '__main__' :

from numpy.distutils.core import setup setup(**configuration (top_path='') .todict ())

Installation of the new package is easy using python setup.py install assuming you have the proper permissions to write to the main site-packages directory for the version of Python you are using. For the resulting package to work, you need to create a file named __init___py (in the same directory as add.pyf). Notice the extension module is defined entirely in terms of the "add.pyf" and "add.f" files. The conversion of the .pyf file to a .c file is handled by numpy.disutils.

0 0

Post a comment