python封装fortran_用Python打包传统的Fortran。可以使用setuptools和numpy.distutils吗?

I am trying to make a python package distribution for some popular Fortran codes in my field. I want it to use the most standard approach with a setup.py file. The related qustion was helpful for learning how to wrap Fortran extensions.

When using this approach, I noticed some confusing behavior when mixing setuptools and numpy.distutils. Is it bad practice to mix the two? As of 2015, it seems preferable to use setuptools as much as possible.

However, I would like to build Fortran extensions in a way that is compatible with numpy. So I would like to import from numpy.distutils to get Extension and setup.

I'm using the following basic approach:

from setuptools.command.develop import develop

from numpy.distutils.core import Extension, setup

ext_modules=[Extension("my_package.fortran_mod", sources=['src/fortran_mod.f'])]

class MyDevelop(develop):

def run(self):

my_script()

develop.run(self)

setup(

...

ext_modules=ext_modules,

cmdclass={'develop':MyDevelop})

This seems to work but I have questions.

Is it generally good practice to mix setuptools and numpy.distribute?

Does the order I import them matter? Should I always import setuptools first?

Is there an official up-to-date tutorial for packaging extensions to numpy? Perhaps even one with some discussion Fortran extensions?

Some links

解决方案This seems to work but I have questions.

Is it generally good practice to mix setuptools and numpy.distribute?

Does the order I import them matter? Should I always import setuptools first?

Is there an official up-to-date tutorial for packaging extensions to numpy? Perhaps even one with some discussion Fortran extensions?

You should not need to use numpy.distribute anymore.

^^ Not necessary

Particularly for wrapping fortran code with numpy, there is the popular f2py. However I personally find the necessary code annotations redundant, because good fortran code contains all necessary information.

(warning personal project plug below)

Recently released is the cleaner fmodpy, which automatically generates all necessary wrapper code in an understandable and clean interface. It supports pre-Fortran90, but is best suited for Fortran90 and later. It could be used to generate a clean distribution along with the python interface of code (presuming users have gfortran installed).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值