3

I have multiple .py files in one package

packageA
    \__init__.py
    \mod1.py
    \mod2.py
    \mod3.py

can I config cython to compile and then packing them all in one packageA.pyd ?

wtayyeb
  • 1,879
  • 2
  • 18
  • 38

1 Answers1

3

Personally, I would better turn all the .py files into .pyx, then include them into the main .pyx of the Cython extension:

packageA.pyx:

include "mod1.pyx" 
include "mod2.pyx" 
include "mod3.pyx" 

Then, compile using a setup.py looking like:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [
        Extension("packageA", sources=["packageA.pyx"])
    ]
)                       

Running this would generate an all in one packageA.pyd binary file. Of course, this will output a single module named packageA, and I don't know if this is acceptable for you, or if you really need distinct modules in your package. But there might be other ways that better fit your question...

Gauthier Boaglio
  • 10,054
  • 5
  • 48
  • 85