基于通过“setuptools”给出的外部值的 Cython 条件编译

3nt*_*3nt 5 python conditional-compilation setuptools cython

我尝试从 Cython pyx 文件有条件地生成 C 代码。我的文档用Cython,我可以使用在发现DEF来定义的值,并IF有条件地生成基于定义的值代码,但如何可以设置为从所述值setup.py通过Extensionsetuptools

谢谢你

3nt*_*3nt 5

谢谢你的链接。

中有趣的标志setup.pycython_compile_time_env。并从 Cython 导入Extension

from setuptools import setup
from Cython.Distutils.extension import Extension

ext = Extension(
    name,
    include_dirs=include_dirs,
    cython_compile_time_env=dict(OPENMP=True),
    sources=['test.pyx'])

setup(name=name,
      cmdclass=dict(build_ext=build_ext),
      ext_modules=[ext])
Run Code Online (Sandbox Code Playgroud)

并在test.pyx

...
IF OPENMP:
#Do openmp
ELSE:
#No openmp
...
Run Code Online (Sandbox Code Playgroud)

Cython 条件语句(IF...ELSE上面)记录在此处