Installing a Python/Cython (extension) module under development

646 views Asked by At

I am constantly working on a Python module which contains C++ extensions wrapped with Cython. The setup.py currently handles the building of the extension module, and is called as python3 setup.py --build_ext --inplace.

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


srcDir = "../src"
src = ["_MyProject.pyx"]    # list of source files

print("source files: {0}".format(src))

modules = [Extension("_MyProject",
                    src,
                    language = "c++",
                    extra_compile_args=["-fopenmp", "-std=c++11", "-O3", "-DNOGTEST"],
                    extra_link_args=["-fopenmp", "-std=c++11"],
                    libraries=["MyProjectLib", "log4cxx"],
                    library_dirs=["../"])]

for e in modules:
    e.cython_directives = {"embedsignature" : True}

setup(name="_MyProject",
     cmdclass={"build_ext": build_ext},
     ext_modules=modules)

On top of the Cython module _MyProject, there is a pure Python module MyProject which imports stuff from _MyProject.

Currently I use and test the module by cd-ing into its directory and importing it from there. How do I need to modify my setup.py so that I can install MyProject into my site packages and have the package always up to date?

1

There are 1 answers

1
kuuko On

Add the argument py_modules = ["MyProject.py",] to your setup() function.