Skip to content

cython doesn't correctly generate C extension with name different from py file #2038

@pitrou

Description

@pitrou

In my setup.py I have the following code:

    from Cython.Build import cythonize

    extensions = [
        Extension("distributed._cy_schedulerstate",
                  ["distributed/schedulerstate.py"])
    ]
    ext_modules = cythonize(extensions)

    setup(..., ext_modules=ext_modules)

The idea is that i can choose at runtime between the pure Python version (distributed.schedulerstate) and the Cython-accelerated version (distributed._cy_schedulerstate). Unfortunately the C extension fails loading:

>>> from distributed import _cy_schedulerstate
Traceback (most recent call last):
  File "<ipython-input-3-6878069d7b91>", line 1, in <module>
    from distributed import _cy_schedulerstate
ImportError: dynamic module does not define module export function (PyInit__cy_schedulerstate)

And indeed the C code generated by Cython doesn't use the extension name defined in the Extension constructor:

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initschedulerstate(void); /*proto*/
PyMODINIT_FUNC initschedulerstate(void)
#else
PyMODINIT_FUNC PyInit_schedulerstate(void); /*proto*/
PyMODINIT_FUNC PyInit_schedulerstate(void)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions