Skip to content

resolver

django_spire.core.management.commands.spire_startapp_pkg.resolver

PathResolver

Resolves file system paths for app and template creation.

This class determines where new Django apps and their templates should be created based on project structure and configuration.

Initializes the path resolver with base directories.

Parameters:

  • base_dir (Path | None, default: None ) –

    Optional base directory for the Django project (defaults to settings.BASE_DIR).

  • template_dir (Path | None, default: None ) –

    Optional template directory (defaults to base_dir/templates).

Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
def __init__(self, base_dir: Path | None = None, template_dir: Path | None = None):
    """
    Initializes the path resolver with base directories.

    :param base_dir: Optional base directory for the Django project (defaults to settings.BASE_DIR).
    :param template_dir: Optional template directory (defaults to base_dir/templates).
    """

    self._base_dir = base_dir or Path(settings.BASE_DIR)
    self._template_dir = template_dir or self._base_dir / 'templates'

get_app_destination

Gets the destination path for a new app based on its components.

For components ['app', 'human_resource', 'employee'], returns Path('base_dir/app/human_resource/employee').

Parameters:

  • components (list[str]) –

    List of app path components.

Returns:

  • Path

    Full path where the app should be created.

Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
def get_app_destination(self, components: list[str]) -> Path:
    """
    Gets the destination path for a new app based on its components.

    For components ['app', 'human_resource', 'employee'], returns
    Path('base_dir/app/human_resource/employee').

    :param components: List of app path components.
    :return: Full path where the app should be created.
    """

    return self._base_dir.joinpath(*components)

get_base_dir

Gets the project's base directory.

Returns:

  • Path

    Base directory path for the Django project.

Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
def get_base_dir(self) -> Path:
    """
    Gets the project's base directory.

    :return: Base directory path for the Django project.
    """

    return self._base_dir

get_template_destination

Gets the destination path for templates based on app components.

Excludes the first component (root app) from the path. For components ['app', 'human_resource', 'employee'], returns Path('templates/human_resource/employee').

Parameters:

  • components (list[str]) –

    List of app path components.

Returns:

  • Path

    Full path where templates should be created.

Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
def get_template_destination(self, components: list[str]) -> Path:
    """
    Gets the destination path for templates based on app components.

    Excludes the first component (root app) from the path. For components
    ['app', 'human_resource', 'employee'], returns
    Path('templates/human_resource/employee').

    :param components: List of app path components.
    :return: Full path where templates should be created.
    """

    template_components = components[1:] if len(components) > 1 else components
    return self._template_dir.joinpath(*template_components)

get_template_dir

Gets the project's template directory.

Returns:

  • Path

    Template directory path for the Django project.

Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
def get_template_dir(self) -> Path:
    """
    Gets the project's template directory.

    :return: Template directory path for the Django project.
    """

    return self._template_dir