0

I have a python package with the following setup.py:

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext


class CMakeExtension(Extension):
    # ...


class CMakeBuild(build_ext):
    # ...


extensions = [
    CMakeExtension("cmake_extension", "path-to-sources"),
    Extension("cython_extension", ["file.pyx"]),
]


setup(
    # ...
    ext_modules=extensions,
    # ...
)

I would like to know if I can call python setup.py build_ext --inplace and build each extension with the appropriate builder.

I am aware of the cmdclass setup function argument but did not find a way to specify that build_ext should be used for the cython extensions and CMakeBuild for the cmake ones.

Note that each extension is building fine with the correct builder class (and the cmdclass argument).

Thanks!

2 Answers 2

1

Your best shot is to ensure CMakeBuild detects the type of extension and reverts back to the original build_ext if the Extension is not an instance of CMakeExtension.

Sign up to request clarification or add additional context in comments.

Comments

0

The workaround I found:

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext


class CMakeExtension(Extension):
    # ...


class CMakeBuild(build_ext):
    # ...


if sys.argv[1] == "build_ext":
    c_ext = [Extension(...)]
elif sys.argv[1] == "build_cmk":
    c_ext = [CMakeExtension(...)]
else:
    raise NotImplementedError


setup(
    # ...
    ext_modules=cythonize(c_ext),
    cmdclass={"build_ext": build_ext, "build_cmk": CMakeBuild},
    # ...
)

And then run:

python setup.py build_ext --inplace
python setup.py build_cmk --inplace

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.