OOF2: The Manual

Name

oof2extutils.get_swig_ext — Run swig and generate Extension objects

Synopsis

from oof2extutils import get_swig_ext

extobj, pkgname = get_swig_ext(srcdir,
                               srcfile,
                               destdir,
                               cext="_wrap.C",
                               include_dirs=[],
                               libraries=[],
                               dry_run=False,
                               force=False,
                               **kwargs) 

Details

get_swig_ext uses swig to generate the code for a Python extension module, and returns a tuple containing an oof2extutils.Extension object and a package name. Both members of the tuple need to be included in the arguments to distutils.core.setup: the Extension object should be included in the ext_modules list and the package name should be included in the packages list.

The name of the swig source file is specified in two parts, srcdir and srcfile, and the output directory is specified by destdir. srcfile doesn't have to be a simple filename — it can contain subdirectory names. If it does, then the output files will be created in a corresponding subdirectory of destdir. Using the same destdir for more than one call to get_swig_ext allows the swig-generated Python packages to be arranged into a package heirarchy.

Return Values

Note that the names given to the return values here are not mandated by the function itself, but are only used for reference.

extobj

The oof2extutils.Extension object created by the function.

pkgname

The name of the generated Python package.

Parameters

srcdir

The name of the directory or directory hierarchy containing the swig source file.

srcfile

The name of the swig source file, relative to the srcdir directory. The value of this parameter may contain subdirectory names. See the discussion above.

destdir

The destination directory, or the base of the destination directory hierarchy.

cext

The filename suffix to use for C++ files created by swig. This argument is optional. The default value is _wrap.C.

include_dirs

A list of directories in which to search for header files, for both swig and the C++ compiler. The C++ compiler will automatically be told to search the directory containing the swig source file, so that directory does not have to be listed here. This argument is optional: its default value is the empty list, [].

libraries

A list of additional libraries to link with when building the Python extension module. The linker will automatically link with the core OOF2 libraries, so they don't have to be included here. This argument is optional: its default value is the empty list, [].

dry_run

This is an optional argument used by distutils to indicate that it should go through the motions of building an extension, but shouldn't actually do anything. The default value is False.

force

This is an optional argument used by distutils to indicate that output files should be recreated even if it appears that they are up-to-date with respect to their source files. The default value is False.

**kwargs

Any keyword arguments allowed by oof2extutils.Extension can be added. They will simply be passed through to the Extension constructor. (The arguments listed above are required because they are used by run_swig.) In particular, one might want to include library_dirs or define_macros. See distutils/extension.py in the Python library for a complete list.