cythonize doesn't work with cython_compile_time_env #1572

Open
sirfz opened this Issue Jan 2, 2017 · 1 comment

Projects

None yet

1 participant

@sirfz
sirfz commented Jan 2, 2017 edited

Python version 2.7.12, Cython version 0.25.1

The following works:

from Cython.Distutils import build_ext  # old_build_ext
from Cython.Distutils import Extension

setup(name='test',
      cmdclass={'build_ext': build_ext},
      ext_modules=[Extension('test', sources=['test.pyx'], language='c++',
                             cython_compile_time_env={'TEST_ENV': 123})])

But the following doesn't:

from setuptools.command.build_ext import build_ext
from Cython.Distutils import Extension

class my_build_ext(build_ext, object):
    def finalize_options(self):
        from Cython.Build.Dependencies import cythonize
        self.distribution.ext_modules[:] = cythonize(
            self.distribution.ext_modules)
        super(my_build_ext, self).finalize_options()

setup(name='test',
      cmdclass={'build_ext': my_build_ext},
      ext_modules=[Extension('test', sources=['test.pyx'], language='c++',
                             cython_compile_time_env={'TEST_ENV': 123})])

cythonize fails with error Compile-time name 'TEST_ENV' not defined.

my_build_ext is basically a copy of Cython.Distutils.built_ext.new_build_ext but it doesn't seem to be compatible with the cython_compile_time_env parameter which is essential for my package.

I'm trying to make my package compatible with new_build_ext but it seems that this is a missing feature or am I missing something?

@sirfz
sirfz commented Jan 2, 2017 edited

Follow-up: The proper parameter to pass to cythonize is compile_time_env instead of cython_compile_time_env but shouldn't this be automatically handled by cythonize when passed an Extension with the cython_compile_time_env attribute set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment