[Numpy-discussion] how to compile Fortran using setup.py
Robert Bradshaw
robertwb@math.washington....
Mon Mar 14 16:00:12 CDT 2011
On Mon, Mar 14, 2011 at 1:44 PM, Ondrej Certik <ondrej@certik.cz> wrote:
> Hi Pearu!
>
> On Sat, Mar 12, 2011 at 2:30 AM, Pearu Peterson
> <pearu.peterson@gmail.com> wrote:
>>
>>
>> On Fri, Mar 11, 2011 at 3:58 AM, Ondrej Certik <ondrej@certik.cz> wrote:
>>>
>>> Hi,
>>>
>>> I spent about an hour googling and didn't figure this out. Here is my
>>> setup.py:
>>>
>>> setup(
>>> name = "libqsnake",
>>> cmdclass = {'build_ext': build_ext},
>>> version = "0.1",
>>> packages = [
>>> 'qsnake',
>>> 'qsnake.calculators',
>>> 'qsnake.calculators.tests',
>>> 'qsnake.data',
>>> 'qsnake.mesh2d',
>>> 'qsnake.tests',
>>> ],
>>> package_data = {
>>> 'qsnake.tests': ['phaml_data/domain.*'],
>>> },
>>> include_dirs=[numpy.get_include()],
>>> ext_modules = [Extension("qsnake.cmesh", [
>>> "qsnake/cmesh.pyx",
>>> "qsnake/fmesh.f90",
>>> ])],
>>> description = "Qsnake standard library",
>>> license = "BSD",
>>> )
>>>
>>
>> You can specify Fortran code, that you don't want to process with f2py, in
>> the libraries list
>> and then use the corresponding library in the extension, for example:
>>
>> setup(...
>> libraries = [('foo', dict(sources=['qsnake/fmesh.f90']))],
>> ext_modules = [Extension("qsnake.cmesh",
>> sources =
>> ["qsnake/cmesh.pyx"],
>> libraries = ['foo']
>> )],
>> ...
>> )
>>
>> See also scipy/integrate/setup.py that resolves the same issue but just
>> using the configuration function approach.
>
> Indeed, I just tried it and it works! Thanks. I am now able to compile
> fortran code into the extension module.
>
> The only problem is that I am not able to convince Cython to also
> parse the .pyx files, it clashes with the numpy's implementation of
> build_ext. Which usually is not a problem, as long as one doesn't need
> to compile Fortran and .pyx at the same time.
In the current Cython tip you can do
ext_modules = cythonize([Extension("qsnake.cmesh", [
"qsnake/cmesh.pyx",
"qsnake/fmesh.f90",
])]),
which will translate the .pyx file to a .c file before hitting distutils.
> So cmake seems like the only robust option anyway.
>
> Ondrej
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list