基于`setuptools`给出的外部值的Cython条件编译 [英] Cython conditional compilation based on external value given via `setuptools`

查看:80
本文介绍了基于`setuptools`给出的外部值的Cython条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to conditionally generate C code from a Cython pyx file. I found in the Cython documentation that I can use DEF to define a value and IF to conditionally generate code based on a defined value, but how can I set the value from the setup.py via Extension from setuptools.

谢谢

推荐答案

谢谢您的链接。

setup.py 中有趣的标志是 cython_compile_time_env 。并从Cython导入扩展名

The interesting flag in the setup.py is cython_compile_time_env. And to import the Extension from Cython.

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])

test.pyx 中:

...
IF OPENMP:
#Do openmp
ELSE:
#No openmp
...

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

Cython conditional statements (IF...ELSE above) are documented here.

这篇关于基于`setuptools`给出的外部值的Cython条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆