Exemplo n.º 1
0
def import_symbols(module, namespace):
    "Import symbols from a module into the namespace, excluding SWIG internals."
    for name in dir(module):
        if name.startswith("_") or name.endswith("_swigregister"):
            continue
        else:
            namespace[name] = getattr(module, name)


if not imported_from_sphinx:
    import petsc4py

    try:
        # Look if petsc4py has already been initialized
        PETSc = petsc4py.__getattribute__('PETSc')
    except AttributeError:
        # If not, initialize petsc4py with the PETSc that PISM was compiled against.
        import sys
        import PISM.version_info
        try:
            petsc4py.init(sys.argv, arch=PISM.version_info.PETSC_ARCH)
        except TypeError:
            # petsc4py on Debian 9 does not recognize the PETSC_ARCH of PETSc in the .deb package
            petsc4py.init(sys.argv)
        from petsc4py import PETSc

    import PISM.cpp

    import_symbols(PISM.cpp, globals())
Exemplo n.º 2
0
"""PISM's Python bindings and SSA inversions tools."""

# See if we have been imported by sphinx.  If so, we won't import any
# packages that are not needed just to compile documentation.
imported_from_sphinx = False
import inspect
caller_mod = inspect.getmodule(inspect.currentframe().f_back)
if (caller_mod is not None) and caller_mod.__name__.startswith("sphinx"):
    imported_from_sphinx = True  # pragma: no cover

if not imported_from_sphinx:
    import petsc4py

    try:
        # Look if petsc4py has already been initialized
        PETSc = petsc4py.__getattribute__('PETSc')
    except AttributeError:
        # If not, initialize petsc4py with the PETSc that PISM was compiled against.
        import sys
        from PISM.petsc_version import PISM_PETSC_ARCH
        petsc4py.init(sys.argv, arch=PISM_PETSC_ARCH)
    from petsc4py import PETSc

    from PISM.cpp import *
    import PISM.cpp

    try:
        import netCDF4 as netCDF
    except ImportError:         # pragma: no cover
        print "netCDF4 is not installed!"
        sys.exit(1)