2

I would like to call the C compiler from my setup.py by using platformer instead of Extension(). How do I add a custom build step to setup.py so that it is run with python setup.py build or any of the other build (bdist_*) commands?

joeforker
  • 40,459
  • 37
  • 151
  • 246
  • related: [Custom distutils commands](http://stackoverflow.com/q/1710839/4279) – jfs Aug 23 '12 at 16:02
  • Today I'd solve this problem by replacing setuptools entirely with a PEP 517 compatible build system. Flit, poetry, https://pypi.org/project/enscons/ – joeforker Jun 25 '20 at 14:00

1 Answers1

2

I don't know what 'platformer' is. I assume that you want a complete control over how C extensions are built while providing the same interface for packaging tools.

A possible way: Cython defines its custom built_ext command that could be used as:

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("example", ["example.pyx"])]
)

A simpler option might be just to include generated C sources into your source tarball and use standard built_ext, Extension classes in setup.py. It would provide the best compatibility with existing tools.

jfs
  • 399,953
  • 195
  • 994
  • 1,670