OOF2: The Manual
Name
oof2extutils.run_swig — Generate the C++ to Python interface code
Synopsis
from oof2extutils import run_swigdict=run_swig(swigfile,destdir,basedir=".",cext="_wrap.C",include_dirs=[],dry_run=False,force=False)
Details
run_swig takes a swig input file,
typically with a .swg or
.i suffix, and creates Python and C++
files that provide the interface between the Python and C++
portions of OOF2.
This function should be called explicitly only if, for some
reason, the function get_swig_ext is
insufficient. get_swig_ext is a
convenient interface to run_swig.
Return Value
run_swig returns a dictionary, called
dict in the synopsis, containing
information about the swig output files. Its entries are:
basename-
The name of the swig input file, with all directories and the suffix removed. If
srcfilewas'foe/fum.swg', thenbasenamewould be'fum'. indir-
The actual directory containing the swig input file. If
srcdirwas'fee/fie'andsrcfilewas'foe/fum.swg', thenindirwould be'fee/fie/foe'. outdir-
The actual directory containing the output files. It's a combination of
destdirand the subdirectory part, if any, ofsrcfile. cfile-
The full name, including the directory, of the C++ file that swig created.
Parameters
srcdir-
The name of the directory containing the swig input file. The name should be given relative to the current directory (where
setup.pyis), or should be an absolute path name (beginning with “/”). swigfile-
The name of the swig input file. Swig input files conventionally have a
.isuffix, but.swgis also used (in particular, it's used by the OOF2 source code). It is not necessary to use a conventional suffix. The file name can be either absolute (beginning with “/”) or relative to thesrcdirdirectory. If the swig input file for the examplepackagedirectory in Figure 7.2, were calledexample.swg, then the correct value of theswigfileparameter would bepackage/example.swg. destdir-
The directory into which the output files will be written. The directory will be created if it doesn't exist. For the example shown in Figure 7.2,
destdirwould bewrapper. The name of this directory is important, because it is the name of the Python package in which the swigged files will be imported into OOF2. cext-
cextis the suffix to use when creating C++ output files. The default value is"_wrap.C", meaning that swig will make an output file calledhigglety_wrap.Cfrom an input file namedhigglety.swg.[45] include_dirs-
include_dirsshould be set to a list of directory names, in which swig will search for files included in its input files with the%includeand%externdirectives. This variable should be set to the predefined list,oof2config.swig_include, with other directories added to it if necessary. dry_run-
Setting
dry_runtoTruewill makerun_swiggo through the motions but not actually do anything. The default value isFalse. This argument can (and should) be omitted. force-
If
forceisTrue, then swig will be run even if the output files already exist and appear to be newer than the input file. This argument can be omitted. If so, it is assumed to beFalse.



