Mixing f2py with distutils
I have "trees" of a python package that contains a myscript.py file that uses a fortran routine.
I usually compile a fortran module with
f2py -c -m calctree calctree.f90
and then I can do
from trees import myscript
myscript.mysub()
which uses calctree.so
If I package everything with distutils by running
python ./setup.py sdist
where is the content of setup.py
#! /usr/bin/env python
from distutils.core import setup
setup(name='trees',
version='0.1',
packages=['trees']
)
and include "include trees / calctree.f90" in the MANIFEST.in file, I can include the .f90 file, but I don't know how to make it compile with f2py on the user's machine and have it. so the file is located in the correct location. Can anyone please help?
Thank!
source to share
You want to use the numpy.distutils.core module, which has its own customization function. Your setup.py file should look something like this (assuming the fortran files are in a directory with tree names),
import numpy.distutils.core
import setuptools
# setup fortran 90 extension
#---------------------------------------------------------------------------
ext1 = numpy.distutils.core.Extension(
name = 'calctree',
sources = ['trees/calc_tree.f90'],
)
# call setup
#--------------------------------------------------------------------------
numpy.distutils.core.setup(
name = 'trees',
version = '0.1',
packages = setuptools.find_packages(),
package_data = {'': ['*.f90']},
include_package_data = True,
ext_modules = [ext1],
)
This should start at a minimum.