我有一个用于一组Fortran90代码的python包装器,我使用f2py构建并使用numpy.distutils打包
我的问题是,除非关闭编译器优化,否则不会构建一个源文件(来自大型复杂项目)。因此,我试图弄清楚如何为传递给numpy.distutils的不同源文件设置不同的编译器优化。
相关的setup.py
文件目前看起来像这样:
def configuration(parent_package='', top_path=None):
global config
from numpy.distutils.misc_util import Configuration
from numpy.distutils.fcompiler import get_default_fcompiler
# figure out which compiler we're going to use
compiler = get_default_fcompiler()
# set some fortran compiler-dependent flags
f90flags = []
if compiler == 'gnu95':
f90flags.append('-fno-range-check')
f90flags.append('-ffree-form')
elif compiler == 'intel' or compiler == 'intelem':
f90flags.append('-132')
# Need zero-level optimization to avoid build problems with one file only!
f90flags.append('-O0')
# Suppress all compiler warnings (avoid huge CI log files)
f90flags.append('-w')
config = Configuration(package_name='mypackage', parent_name=parent_package, top_path=top_path)
config.add_extension(name='_mypackage',
sources=[mypackage_gen_source],
extra_f90_compile_args=f90flags,
f2py_options=['--quiet'],
)
return config
def mypackage_gen_source(ext, build_dir):
# ... some code that assembles a list of file paths called sourcelist
config.have_f90c()
return sourcelist
if __name__ == '__main__':
from numpy.distutils.core import setup
setup(configuration=configuration)
有没有办法告诉numpy.distutils为不同的文件使用不同的标志?
如果无法做到这一点,那么构建和打包这样一个大项目的更好方法是什么?