def build_stubs(modules: List[str], options: Options, find_submodules: bool=False) -> List[str]:
    'Uses mypy to construct stub objects for the given modules.\n\n    This sets global state that ``get_stub`` can access.\n\n    Returns all modules we might want to check. If ``find_submodules`` is False, this is equal\n    to ``modules``.\n\n    :param modules: List of modules to build stubs for.\n    :param options: Mypy options for finding and building stubs.\n    :param find_submodules: Whether to attempt to find submodules of the given modules as well.\n\n    '
    data_dir = mypy.build.default_data_dir()
    search_path = mypy.modulefinder.compute_search_paths([], options, data_dir)
    find_module_cache = mypy.modulefinder.FindModuleCache(search_path, fscache=None, options=options)
    all_modules = []
    sources = []
    for module in modules:
        all_modules.append(module)
        if (not find_submodules):
            module_path = find_module_cache.find_module(module)
            if (not isinstance(module_path, str)):
                continue
            sources.append(mypy.modulefinder.BuildSource(module_path, module, None))
        else:
            found_sources = find_module_cache.find_modules_recursive(module)
            sources.extend(found_sources)
            all_modules.extend((s.module for s in found_sources if (s.module not in all_modules)))
    try:
        res = mypy.build.build(sources=sources, options=options)
    except mypy.errors.CompileError as e:
        output = [_style('error: ', color='red', bold=True), 'not checking stubs due to failed mypy compile:\n', str(e)]
        print(''.join(output))
        raise RuntimeError from e
    if res.errors:
        output = [_style('error: ', color='red', bold=True), 'not checking stubs due to mypy build errors:\n']
        print((''.join(output) + '\n'.join(res.errors)))
        raise RuntimeError
    global _all_stubs
    _all_stubs = res.files
    return all_modules
Uses mypy to construct stub objects for the given modules.

This sets global state that ``get_stub`` can access.

Returns all modules we might want to check. If ``find_submodules`` is False, this is equal
to ``modules``.

:param modules: List of modules to build stubs for.
:param options: Mypy options for finding and building stubs.
:param find_submodules: Whether to attempt to find submodules of the given modules as well.
def build_stubs(modules: List[str], options: Options, find_submodules: bool=False) -> List[str]:
    'Uses mypy to construct stub objects for the given modules.\n\n    This sets global state that ``get_stub`` can access.\n\n    Returns all modules we might want to check. If ``find_submodules`` is False, this is equal\n    to ``modules``.\n\n    :param modules: List of modules to build stubs for.\n    :param options: Mypy options for finding and building stubs.\n    :param find_submodules: Whether to attempt to find submodules of the given modules as well.\n\n    '
    data_dir = mypy.build.default_data_dir()
    search_path = mypy.modulefinder.compute_search_paths([], options, data_dir)
    find_module_cache = mypy.modulefinder.FindModuleCache(search_path, fscache=None, options=options)
    all_modules = []
    sources = []
    for module in modules:
        all_modules.append(module)
        if (not find_submodules):
            module_path = find_module_cache.find_module(module)
            if (not isinstance(module_path, str)):
                continue
            sources.append(mypy.modulefinder.BuildSource(module_path, module, None))
        else:
            found_sources = find_module_cache.find_modules_recursive(module)
            sources.extend(found_sources)
            all_modules.extend((s.module for s in found_sources if (s.module not in all_modules)))
    try:
        res = mypy.build.build(sources=sources, options=options)
    except mypy.errors.CompileError as e:
        output = [_style('error: ', color='red', bold=True), 'not checking stubs due to failed mypy compile:\n', str(e)]
        print(.join(output))
        raise RuntimeError from e
    if res.errors:
        output = [_style('error: ', color='red', bold=True), 'not checking stubs due to mypy build errors:\n']
        print((.join(output) + '\n'.join(res.errors)))
        raise RuntimeError
    global _all_stubs
    _all_stubs = res.files
    return all_modules