コード例 #1
0
ファイル: __init__.py プロジェクト: tigercomputing/vortex
def check_modules(install=False):
    """
    Check for the presence of various required modules.

    If the ``install`` parameter is ``True``, an attempt will be made to
    install missing modules using :func:`install_package`. Any available
    required modules will be loaded into the running process as a side-effect
    of running this function.
    """
    missing = set()

    # Try to load all the modules in our required set. If we fail, add the
    # missing modules to the missing set.
    for module in _REQUIRE_MODULES:
        try:
            import_module(module)
        except ImportError:
            logger.debug("Detected missing required module: {mod}".format(
                mod=module))
            missing.add(module)

    # Have we already got all the modules? Great!
    if not missing:
        return

    # Have we been asked to install the missing ones?
    if not install:
        raise EnvironmentException(
            "Required Python modules are missing: {modules}".format(
                modules=", ".join(sorted(missing))))

    # Now try to install the missing modules
    for module in missing:
        logger.info("Installing Python module: {mod}".format(mod=module))
        install_package(_REQUIRE_MODULES[module])

    # Re-check all the modules
    missing.clear()
    for module in _REQUIRE_MODULES:
        try:
            import_module(module)
        except ImportError:
            logger.debug("Detected missing required module: {mod}".format(
                mod=module))
            missing.add(module)

    if not missing:
        return

    # We failed to install the modules :-(
    raise EnvironmentException(
        "Required Python modules could not be installed: {modules}".format(
            modules=", ".join(sorted(missing))))
コード例 #2
0
ファイル: __init__.py プロジェクト: tigercomputing/vortex
    def __locate(cls, module):
        try:
            return cls.__registered[module]
        except KeyError:
            pass

        try:
            import_module(module)
        except ImportError:
            raise AcquisitionError(
                "Cannot import acquirer module {mod}.".format(mod=module))

        try:
            return cls.__registered[module]
        except KeyError:
            raise AcquisitionError(
                "Could not find any registered acquirer modules in {mod}"
                .format(mod=module))
コード例 #3
0
ファイル: __init__.py プロジェクト: tigercomputing/vortex
    def __locate(cls, module):
        try:
            return cls.__registered[module]
        except KeyError:
            pass

        try:
            import_module(module)
        except ImportError:
            raise DeploymentError(
                "Cannot import deployment handler module {mod}.".format(
                    mod=module))

        try:
            return cls.__registered[module]
        except KeyError:
            raise DeploymentError(
                "Could not find any registered deployment modules in {mod}"
                .format(mod=module))