6. The Wrapper Script¶
The script mod is a convenience script primarily for starting the Python
interpreter and after its exit execute PostMØD (the summary generator).
The execution can however be customised somewhat, e.g., by running the
interpreter through valgrind and/or gdb/lldb, or switching the
interpreter into interactive mode.
The wrapper script does the following.
Clear the folder
out/. If it does not exist, if will be created. All printing functions in libMØD assumesout/is created.Create an input Python script (
out/input) with some default code, and then code based on the command line parameters (see-fand-e).Run the Python interpreter on the input script, optionally through debugging tools.
If the exit code of the executable is not 0, exit with that exit code.
If PostMØD is not selected to be run, exit with code 0.
Run PostMØD and exit with its exit code.
6.1. Usage¶
mod [options]
6.1.1. Meta Options¶
- --help, -h¶
Shows the help output of the script.
- --version, -v¶
Print the version of MØD and exit (the version is always printed in the start).
6.1.2. Input Options¶
- -f <filename>¶
Append
include("filename")to the input script (seeinclude()). This option can be repeated to execute multiple files in sequence.
- -e <code>¶
Append the given code (and a line break) to the input script. This option can be repeated to execute multiple code snippets in sequence.
- MOD_NO_DEPRECATED¶
When this environment variable is set to a non-empty string, then the string
config.common.ignoreDeprecation = Falseis executed first. This can be used to force errors when scripts use deprecated functionality.
- MOD_ILP_SOLVER¶
When this environment varaible is set to a non-empty string, then the string
config.ilp.solver = "ilpSolver"whereilpSolveris the value of the this environment variable, is execute first. Whenever thedefaultsolver is requested, this one will be selected. See alsogetAvailableILPSolvers()/getAvailableILPSolvers().
6.1.3. Execution Customization¶
- -i¶
Use interactive mode for the Python interpreter (i.e., pass
-ias additional argument to the interpreter), but disable the log. Ifipython3is available it will be used as interpreter, otherwisepython3is used. See alsoMOD_PYTHONandMOD_IPYTHON.
- -q¶
Do not print messages from the wrapper script and the
include()function. This does not influence the library.
- MOD_PYTHON¶
Set this environment variable to the executable to start in non-interactive mode. If not set it will use a Python interpreter appropriate for the compiled bindings. This interpreter was found during configuration of the build system. When executing the wrapper script the exact command can be seen in the output.
- MOD_IPYTHON¶
Set this environment variable to the executable to start in interactive mode (when
-iis given). If not setipython3will be used, if it can be found, otherwise it will fall back to standard Python interpreter as if-iwas not given.Warning
The standard
ipython3may not be appropriate for the compiled bindings, which may result in a crash during import of themodmodule.
- MOD_DEBUGGER¶
Set this environmentt variable to the executable to use with
--debugis given and--memcheckis not given. When not set the stringgdb --argsorlldb --is used, if GDB or LLDB is available.
6.1.4. Post-processing Options¶
- --nopost¶
Do not run PostMØD after the selected executable has finished.
- clean¶
Do not run anything, but remove the
outandsummaryfolders.
6.1.5. Debugging Options¶
- --profile¶
Run the interpreter through Valgrind with
--tool=callgrind. This option takes precedence over thememcheckoption.
- --memcheck¶
Run the interpreter through Valgrind with standard options for memory check. If
--debugis given as well, the options--vgdb=yes --vgdb-error=0are also given tovalgrindsuch that a debugger (e.g. GDB or LLDB) can be attached.
- --vgArgs <args>¶
If either
--profileor--memcheckis used, this inserts<args>as an extra argument forvalgrind.
- --debug¶
Run the interpreter through GDB, or LLDB. If
MOD_DEBUGGERit set, then this string is prepended to form a complete command, otherwise ifgdbis available, thengdb --argsis preprended, otherwise iflldb``is available, then ``lldb --is prepended, otherwise the script stops with an error.If
--memcheckis given as well, then it takes preceedence, but it will add extra flags to start a gdbserver. This will make Valgrind wait for a debugger to be attached. Valgrind will print instructions for how to attach GDB.
6.2. PyMØD Preamble¶
When the wrapper script creates the input script, it will start with a small
preamble of useful code before the user-defined code.
The complete code, including the preamble, given to the Python interpereter can
be seen in out/input after execution of the wrapper script.
The preamble has the following effects.
Setting
RTLD_GLOBALin the interpretersdlopenflags (see Creating a Python Extension)import modandfrom mod import *Defining the following function both in global scope and in the
modmodule.- mod.include(fName, checkDup=True, putDup=True, skipDup=True)¶
Include the file
fNamein somewhat the same way that the#includedirective in the C/C++ preprocessor includes files. Paths are handled relatively using the functionsprefixFilename(),pushFilePrefix(), andpopFilePrefix().- Parameters:
fName (str) – the file to be included.
checkDup (bool) – check if the file has already been included before (with
putDup=True)putDup (bool) – remember that this file has been included in subsequent calls.
skipDup (bool) – skip inclusion instead of exiting if the file has already been included before (with
putDup=True)
6.3. Plugins (Loading of Additional Modules)¶
It can be useful to always import additional modules when using MØD. This can be achieved by writing a file in the following format:
name: <module name>
path: <Python import path>
When mod uses such a file, it will append <Python import path> to
PYTHONPATH,
and insert both import <module name> and from <module name> import *
into the preamble.
The plugin specification file must be placed in a directory that is also
mentioned in the following environment variable.
- MOD_PLUGIN_PATH¶
A colon separated list of paths to search for plugins. Non-directory paths are skipped. All files (non-recursively) in each specified directory are checked for plugin information.