def iter_modules(package: str) -> List[str]:
    """Get names of modules from *package*, depending on execution environment.

    .. note::
        If being packaged with PyInstaller, modules aren't discoverable dynamically by scanning source directory because
        :class:`importlib.machinery.FrozenImporter` doesn't implement :func:`iter_modules`. But it is still possible to
        find all potential modules by iterating through ``toc``, which contains list of all "frozen" resources.

    :param package: a package name to search modules in, e.g. ``patroni.dcs``.

    :returns: list of known module names with absolute python module path namespace, e.g. ``patroni.dcs.etcd``.
    """
    module_prefix = package + '.'

    if getattr(sys, 'frozen', False):
        toc: Set[str] = set()
        # dirname may contain a few dots, which causes pkgutil.iter_importers()
        # to misinterpret the path as a package name. This can be avoided
        # altogether by not passing a path at all, because PyInstaller's
        # FrozenImporter is a singleton and registered as top-level finder.
        for importer in pkgutil.iter_importers():
            if hasattr(importer, 'toc'):
                toc |= getattr(importer, 'toc')
        # If it found the pyinstaller toc then use it, otherwise fall through to default
        # behavior which works in pyinstaller >= 4.4
        if len(toc) > 0:
            dots = module_prefix.count('.')  # search for modules only on the same level
            return [module for module in toc if module.startswith(module_prefix) and module.count('.') == dots]

    # here we are making an assumption that the package which is calling this function is already imported
    pkg_file = sys.modules[package].__file__
    if TYPE_CHECKING:  # pragma: no cover
        assert isinstance(pkg_file, str)
    return [name for _, name, is_pkg in pkgutil.iter_modules([os.path.dirname(pkg_file)], module_prefix) if not is_pkg]
Get names of modules from *package*, depending on execution environment.

    .. note::
        If being packaged with PyInstaller, modules aren't discoverable dynamically by scanning source directory because
        :class:`importlib.machinery.FrozenImporter` doesn't implement :func:`iter_modules`. But it is still possible to
        find all potential modules by iterating through ``toc``, which contains list of all "frozen" resources.

    :param package: a package name to search modules in, e.g. ``patroni.dcs``.

    :returns: list of known module names with absolute python module path namespace, e.g. ``patroni.dcs.etcd``.
    
patroni/dynamic_loader.py