def METHOD_NAME(pkg, path=None):
    """Get all modules in a package."""
    context = {}
    if path is None:
        path = pkg.__path__
    elif type(path) is not list:
        path = [path]
    for loader, name, _ in pkgutil.walk_packages(path):
        try:
            module = loader.find_module(name).load_module(name)
            pkg_names = getattr(module, '__all__', None)
            for k, v in vars(module).items():
                if not k.startswith('_') and (pkg_names is None or k in pkg_names):
                    context[k] = v
            context[name] = module
        except AppRegistryNotReady:  # pragma: no cover
            pass
        except Exception as error:
            # this 'protects' against malformed plugin modules by more or less silently failing
            # log to stack
            log_error({name: str(error)}, 'discovery')
    return [v for k, v in context.items()]