C/C++ extensions
The previous chapter already covered this somewhat, as it's a requirement to compile the C/C++ files. But that chapter didn't explain what and how the setup.py was doing in this case.
For convenience, we will repeat the setup.py file:
import setuptools
spam = setuptools.Extension('spam', sources=['spam.c'])
setuptools.setup(
name='Spam',
version='1.0',
ext_modules=[spam],
)Before you start with these extensions, you should learn the following commands:
build: This is actually not a C/C++ specific build function (trybuild_clibfor that) but a combined build function to build everything withinsetup.py.clean: This cleans the results from thebuildcommand. This is generally not needed but sometimes the detection of files that need to be recompiled to work is incorrect. So if you encounter strange or unexpected issues, try cleaning the project first.
Regular extensions
The setuptools.Extension class tells setuptools...