[Numpy-discussion] distutils for a Pyrex module

Robert Kern robert.kern at gmail.com
Tue Mar 20 17:46:28 EDT 2007


Pierre GM wrote:
> All,
> I'm trying to write a numpy.distutils setup.py for a pyrex module that 
> involves both external C and fortran sources, and where the fortran sources 
> need to be linked w/ blas and lapack. Here's what I have so far:
> 
> ##################################
> def configuration(parent_package='',top_path=None):
>     from numpy.distutils.misc_util import Configuration, get_mathlibs
>     config = Configuration('cloess',parent_package,top_path)
>     from numpy.distutils.system_info import get_info, dict_append
> 
>     libs = []
>     generate_libraries = []
>     f_sources = ['loessf.f', 'linpack_lite.f']
>     c_sources = ['loess.c', 'loessc.c', 'misc.c', 'predict.c',]
>     #
>     blas_info = get_info('blas_opt')
>     lapack_info = get_info('lapack_opt')
>     build_info = {}
>     dict_append(build_info, **blas_info)
>     dict_append(build_info, **lapack_info)    
>     #
>     config.add_extension('cloess',
>                          sources=[join('src', x) for x in 
> (f_sources+c_sources)],
>                          depends = [join('src','*.h'),
>                                     join('src','*.pyx'),
>                                     join('src','*.pxd')
>                                     ],
>                          **build_info
>                         )
>     config.add_data_dir(join('.','examples'))
>     config.add_data_files('pyloess.py')

This line *should* be unnecessary. .py files should be picked up automatically.

>     return config
> ############################
> 
> But that doesn't do what I want: during the setup, the .f files are processed 
> by f2py. I don't need that, I just want to have the Fortran files compiled 
> along the C sources. What's the M.O., then ?

The first file in the sources list should be the one that actually implements
the module, i.e. the C file generated by Pyrex. FORTRAN files specified after
the first one won't be processed by f2py.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list