[SciPy-User] Issues with f2py/distutils

Jose Gomez-Dans jgomezdans@gmail....
Fri Jun 15 11:03:06 CDT 2012


I'm trying to package some fortran code and wrappers that use f2py. I
have a pyf file, and I want a setup file that will compile and install
the library. Also, I will need several versions of the same library
available. In the past, we just compiled libraries with different
names, and used that. I read that a wrapper trick can be used (see
here: http://cens.ioc.ee/pipermail/f2py-users/2004-September/000921.html).

My problem comes when trying to package and use the above. Our
software requires a configuration file to specify a module name to
load. This module will be the Fortran code above. In the past, we used
different named versions (like my_module1, my_module2, etc) of the
module, as the module has common statements that otherwise get trashed
between calls. Following the "recipe" in the above link, and having my
code organised as follows

       *.f, *.f90 # fortran files

I basically want my compiled fortran extension to appear in
my_extension/my_extension/, and in __init__ I use the trick in the
recipe to add a new class wraps the fortran library

class MyExtension(object):
    def __init__(self, *args, **kwargs):
        myextension_mod = MExt('<my_extension>') # This is the so file
        self.myextension = myextension_mod._module

You can then do this:

import my_extension
m = my_extension.MyExtension()
m.myextension.<access the fortran methods>

However, I'd basically want to just do
from my_extension import <fortran methods>

Is this possible? And if it is, how do you go about that? Also, my
current setup.py compiles the code and puts it above the main package
directory, not inside that directory (my_extension/my_extension).
Here's what my setup.py file looks like

from numpy.distutils.core import setup

import sys, os
def configuration ( parent_package='', top_path=None ):
    from numpy.distutils.misc_util import Configuration
    config = Configuration(parent_package=parent_package,top_path=top_path, )

    config.add_extension ('extension_name',
        sources = [ 'blah.f', 'blahblah.f'] )
    return config

setup ( configuration = configuration,
    package_dir={'my_extension': 'my_extension'}


More information about the SciPy-User mailing list