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
srcfile
was'foe/fum.swg'
, thenbasename
would be'fum'
. indir
-
The actual directory containing the swig input file. If
srcdir
was'fee/fie'
andsrcfile
was'foe/fum.swg'
, thenindir
would be'fee/fie/foe'
. outdir
-
The actual directory containing the output files. It's a combination of
destdir
and 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.py
is), or should be an absolute path name (beginning with “/”). swigfile
-
The name of the swig input file. Swig input files conventionally have a
.i
suffix, but.swg
is 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 thesrcdir
directory. If the swig input file for the examplepackage
directory in Figure 7.2, were calledexample.swg
, then the correct value of theswigfile
parameter 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,
destdir
would 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
-
cext
is 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.C
from an input file namedhigglety.swg
.[45] include_dirs
-
include_dirs
should be set to a list of directory names, in which swig will search for files included in its input files with the%include
and%extern
directives. This variable should be set to the predefined list,oof2config.swig_include
, with other directories added to it if necessary. dry_run
-
Setting
dry_run
toTrue
will makerun_swig
go through the motions but not actually do anything. The default value isFalse
. This argument can (and should) be omitted. force
-
If
force
isTrue
, 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
.