Cython conditional compile based on external value -


i try conditionally compile (or generate) c code cython pxd. read can def define aa value , if conditionally generate based on value, how can value outside of pxd file?

specifically these 2 cases interesting me now:

  • give command-line define cython, preferrably through cython.distutils setuptools way
  • the extern-ed c header file defines value, , conditionally define using cython based on value (maybe impossible now?)

thank you

you generate pxi file, , include before doing if (same ./configure generate config.h too.) in kivy setup.py example :

c_options = {  'use_opengl_es2': true, 'use_opengl_debug': false, 'use_glew': false, 'use_mesagl': false}  print 'generate config.pxi' open(join(dirname(__file__), 'kivy', 'graphics', 'config.pxi'), 'w') fd:     k, v in c_options.iteritems():         fd.write('def %s = %d\n' % (k.upper(), int(v))) 

and then, in pxd :

include "config.pxi" if use_opengl_debug == 1:   # other import or whatever want 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -