Skip to content

registry

django_spire.core.management.commands.spire_startapp_pkg.registry

AppRegistry

Manages Django app registration information.

This class provides methods to query which apps are installed in the Django project and validate app component hierarchies.

get_installed_apps

Gets a list of all installed app names.

Returns:

  • list[str]

    List of fully qualified app names from Django's app registry.

Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
def get_installed_apps(self) -> list[str]:
    """
    Gets a list of all installed app names.

    :return: List of fully qualified app names from Django's app registry.
    """

    return [config.name for config in apps.get_app_configs()]

get_missing_components

Identifies which app components in a path are not registered.

For a path like ['app', 'human_resource', 'employee'], this checks if 'app', 'app.human_resource', and 'app.human_resource.employee' are registered, and returns those that are missing.

Parameters:

  • components (list[str]) –

    List of app path components to check.

Returns:

  • list[str]

    List of unregistered component paths.

Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
def get_missing_components(self, components: list[str]) -> list[str]:
    """
    Identifies which app components in a path are not registered.

    For a path like ['app', 'human_resource', 'employee'], this checks
    if 'app', 'app.human_resource', and 'app.human_resource.employee'
    are registered, and returns those that are missing.

    :param components: List of app path components to check.
    :return: List of unregistered component paths.
    """

    registry = self.get_installed_apps()
    missing = []

    total = len(components)

    for i in range(total):
        component = '.'.join(components[: i + 1])

        if component not in registry and i > 0:
            missing.append(component)

    return missing

get_valid_root_apps

Gets all valid root app names from INSTALLED_APPS.

Returns root-level apps (first component before a dot) that can be used as parent apps, excluding Django's built-in apps.

Returns:

  • set[str]

    Set of valid root app names.

Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
def get_valid_root_apps(self) -> set[str]:
    """
    Gets all valid root app names from INSTALLED_APPS.

    Returns root-level apps (first component before a dot) that can be
    used as parent apps, excluding Django's built-in apps.

    :return: Set of valid root app names.
    """

    return {
        app.split('.')[0]
        for app in settings.INSTALLED_APPS
        if '.' in app and app.split('.')[0] != 'django'
    }

is_app_registered

Checks if an app path is registered in Django.

Parameters:

  • app_path (str) –

    Dot-separated app path to check.

Returns:

  • bool

    True if the app is registered, False otherwise.

Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
def is_app_registered(self, app_path: str) -> bool:
    """
    Checks if an app path is registered in Django.

    :param app_path: Dot-separated app path to check.
    :return: True if the app is registered, False otherwise.
    """

    return app_path in self.get_installed_apps()