0

I am packaging a project involving cython extensions inside a namespace package. My folder structure looks as follows

.
├── namespace_package
│   └── package
|       ├── extension.pxd
|       ├── extension.pyx
│       └── __init__.py
└── setup.py

My setup script looks as follows:

from setuptools import setup
from setuptools.extension import Extension

# factory function
def my_build_ext(pars):
    # import delayed:
    from setuptools.command.build_ext import build_ext as _build_ext

    # include_dirs adjusted: 
    class build_ext(_build_ext):
        def finalize_options(self):
            _build_ext.finalize_options(self)
            # Prevent numpy from thinking it is still in its setup process:
            __builtins__.__NUMPY_SETUP__ = False
            import numpy
            self.include_dirs.append(numpy.get_include())

    #object returned:
    return build_ext(pars)

extensions = [Extension(namespace_package.package.extension, ['namespace_package\\package\\extension.pyx']]

setup(
    cmdclass={'build_ext' : my_build_ext},
    setup_requires=['cython', 'numpy'],
    install_requires=['cython', 'numpy'], 
    packages=['namespace_package.package'],
    ext_modules=extensions
)

Here, I used the tricks to delay the import of numpy and cython as described here, and my solution is inspired by this solution.

The problem is that extension.pxd is not found or processed. That is, declarations made in extension.pxd are not available and I get the corresponding errors.

How do I do the setup properly so that all files are found and processed?

Samufi
  • 2,465
  • 3
  • 19
  • 43
  • https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules – ead Dec 30 '19 at 12:51
  • Actually this https://stackoverflow.com/a/49502296/5769463 already provides the answer, but one has to follow the link to github. – ead Dec 30 '19 at 12:54
  • @ead Thanks for the helpful links. It may be a worthwhile alternative to distribute the c files only. I will investigate further. – Samufi Dec 30 '19 at 13:34

0 Answers0