'This method is very similar to importlib\'s `_gcd_import`.'

def _do_import(self, import_path, sys_path):

    import_parts = [(i.value if isinstance(i, tree.Name) else i) for i in import_path]
    if ((len(import_path) > 2) and (import_parts[:2] == ['flask', 'ext'])):
        ipath = ((('flask_' + str(import_parts[2])),) + import_path[3:])
        modules = self._do_import(ipath, sys_path)
        if modules:
            return modules
        else:
            return self._do_import((('flaskext',) + import_path[2:]), sys_path)
    module_name = '.'.join(import_parts)
    try:
        return set([self._evaluator.modules[module_name]])
    except KeyError:
        pass
    if (len(import_path) > 1):
        bases = self._do_import(import_path[:(-1)], sys_path)
        if (not bases):
            return set()
        parent_module = list(bases)[0]
        if (import_parts == ['os', 'path']):
            return parent_module.py__getattribute__('path')
        try:
            method = parent_module.py__path__
        except AttributeError:
            _add_error(self.module_context, import_path[(-1)])
            return set()
        else:
            paths = method()
            debug.dbg('search_module    %s    in    paths    %s', module_name, paths)
            for path in paths:
                try:
                    if (not isinstance(path, list)):
                        path = [path]
                    (module_file, module_path, is_pkg) = find_module(import_parts[(-1)], path, fullname=module_name)
                    break
                except ImportError:
                    module_path = None
            if (module_path is None):
                _add_error(self.module_context, import_path[(-1)])
                return set()
    else:
        parent_module = None
        try:
            debug.dbg('search_module    %s    in    %s', import_parts[(-1)], self.file_path)
            (sys.path, temp) = (sys_path, sys.path)
            try:
                (module_file, module_path, is_pkg) = find_module(import_parts[(-1)], fullname=module_name)
            finally:
                sys.path = temp
        except ImportError:
            _add_error(self.module_context, import_path[(-1)])
            return set()
    code = None
    if is_pkg:
        if module_path.endswith(('.zip', '.egg')):
            code = module_file.loader.get_source(module_name)
        else:
            module_path = get_init_path(module_path)
    elif module_file:
        code = module_file.read()
        module_file.close()
    if isinstance(module_path, ImplicitNSInfo):
        from jedi.evaluate.representation import ImplicitNamespaceContext
        (fullname, paths) = (module_path.name, module_path.paths)
        module = ImplicitNamespaceContext(self._evaluator, fullname=fullname)
        module.paths = paths
    elif ((module_file is None) and (not module_path.endswith(('.py', '.zip', '.egg')))):
        module = compiled.load_module(self._evaluator, module_path)
    else:
        module = _load_module(self._evaluator, module_path, code, sys_path, parent_module)
    if (module is None):
        return set()
    self._evaluator.modules[module_name] = module
    return set([module])
