""" Tools for building F2PY generated extension modules. ----- Permission to use, modify, and distribute this software is given under the terms of the NumPy License. See http://scipy.org. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. Author: Pearu Peterson Created: Oct 2006 ----- """ import os import re import sys import tempfile try: from numpy import __version__ as numpy_version except ImportError: numpy_version = 'N/A' __all__ = ['main', 'compile'] __usage__ = """ F2PY G3 --- The third generation of Fortran to Python Interface Generator ========================================================================= Description ----------- f2py program generates a Python C/API file (module.c) that contains wrappers for given Fortran functions and data so that they can be accessed from Python. With the -c option the corresponding extension modules are built. Options ------- --g3-numpy Use numpy.f2py.lib tool, the 3rd generation of F2PY, with NumPy support. --2d-numpy Use numpy.f2py tool with NumPy support. [DEFAULT] --2d-numeric Use f2py2e tool with Numeric support. --2d-numarray Use f2py2e tool with Numarray support. -m Name of the module; f2py generates a Python/C API file module.c or extension module . For wrapping Fortran 90 modules, f2py will use Fortran module names. --parse Parse Fortran files and print result to stdout. Options effective only with -h ------------------------------ -h Write signatures of the fortran routines to file and exit. You can then edit and use it instead of for generating extension module source. If is stdout or stderr then the signatures are printed to the corresponding stream. --overwrite-signature Overwrite existing signature file. Options effective only with -c ------------------------------ -c Compile fortran sources and build extension module. --build-dir All f2py generated files are created in . Default is tempfile.mktemp() and it will be removed after f2py stops unless is specified via --build-dir option. numpy.distutils options effective only with -c ---------------------------------------------- --fcompiler= Specify Fortran compiler type by vendor Extra options effective only with -c ------------------------------------ -L/path/to/lib/ -l -D -U -I/path/to/include/ .o .(so|dynlib|dll) .a Using the following macros may be required with non-gcc Fortran compilers: -DPREPEND_FORTRAN -DNO_APPEND_FORTRAN -DUPPERCASE_FORTRAN -DUNDERSCORE_G77 -DF2PY_DEBUG_PYOBJ_TOFROM --- pyobj_(to|from)_ functions will print debugging messages to stderr. """ import re import shutil import parser.api from parser.api import parse, PythonModule, EndStatement, Module, Subroutine, Function,\ get_reader def get_values(sys_argv, prefix='', suffix='', strip_prefix=False, strip_suffix=False): """ Return a list of values with pattern . The corresponding items will be removed from sys_argv. """ match = re.compile(prefix + r'.*' + suffix + '\Z').match ret = [item for item in sys_argv if match(item)] [sys_argv.remove(item) for item in ret] if strip_prefix and prefix: i = len(prefix) ret = [item[i:] for item in ret] if strip_suffix and suffix: i = len(suffix) ret = [item[:-i] for item in ret] return ret def get_option(sys_argv, option, default_return = None): """ Return True if sys_argv has