def autodiscover(module_name=None):
    """
    Autodiscover INSTALLED_APPS perms.py modules and fail silently when not
    present. This forces an import on them to register any permissions bits
    they may want.
    """
    from django.utils.module_loading import module_has_submodule
    from permission.compat import import_module
    from permission.conf import settings

    module_name = module_name or settings.PERMISSION_AUTODISCOVER_MODULE_NAME
    app_names = (app.name for app in apps.app_configs.values())

    for app in app_names:
        mod = import_module(app)
        # Attempt to import the app's perms module
        try:
            # discover the permission module
            discover(app, module_name=module_name)
        except:
            # Decide whether to bubble up this error. If the app just doesn't
            # have an perms module, we can just ignore the error attempting
            # to import it, otherwise we want it to bubble up.
            if module_has_submodule(mod, module_name):
                raise
Autodiscover INSTALLED_APPS perms.py modules and fail silently when not
    present. This forces an import on them to register any permissions bits
    they may want.