def _find_module(module, path=None):
    mod_base = module
    parent_path = None
    while '.' in mod_base:
            first, _, mod_base = mod_base.partition('.')
            parent_path = path
            _, path, _ = imp.find_module(first, path)
            path = [path]
    try:
        _, path, _ = imp.find_module(mod_base, path)
    except ImportError:
        # NOTE(bnemec): There are two reasons we might get here: 1) A
        # non-module import and 2) an import of a namespace module that is
        # in the same namespace as the current project, which caused us to
        # recurse into the project namespace but fail to find the third-party
        # module.  For 1), we won't be able to import it as a module, so we
        # return the parent module's path, but for 2) the import below should
        # succeed, so we re-raise the ImportError because the module was
        # legitimately not found in this path.
        try:
            __import__(module)
        except ImportError:
            # Non-module import, return the parent path if we have it
            if parent_path:
                return parent_path
            raise
        raise
    return path
dataset/ETHPy150Open openstack/sahara/sahara/utils/hacking/import_checks.py/_find_module/original