3.3 Describing extension modules

Just as writing Python extension modules is a bit more complicated than writing pure Python modules, describing them to the Distutils is a bit more complicated. Unlike pure modules, it's not enough just to list modules or packages and expect the Distutils to go out and find the right files; you have to specify the extension name, source file(s), and any compile/link requirements (include directories, libraries to link with, etc.).

All of this is done through another keyword argument to setup(), the extensions option. extensions is just a list of Extension instances, each of which describes a single extension module. Suppose your distribution includes a single extension, called foo and implemented by foo.c. If no additional instructions to the compiler/linker are needed, describing this extension is quite simple:

Extension("foo", ["foo.c"])
The Extension class can be imported from distutils.core, along with setup(). Thus, the setup script for a module distribution that contains only this one extension and nothing else might be:
from distutils.core import setup, Extension
setup(name = "foo", version = "1.0",
      ext_modules = [Extension("foo", ["foo.c"])])

The Extension class (actually, the underlying extension-building machinery implemented by the built_ext command) supports a great deal of flexibility in describing Python extensions, which is explained in the following sections.


Subsections

See About this document... for information on suggesting changes.