Skip to content

local

dev_tool.services.execution.local

log = logging.getLogger(__name__) module-attribute

LocalExecutionStrategy

Bases: ExecutionStrategy

An execution strategy for local development with only the database in Docker.

This is the legacy mode where Django runs locally and only PostgreSQL runs in a container.

The constructor for the LocalExecutionStrategy class.

Parameters:

Source code in dev_tool/services/execution/local.py
def __init__(self, docker_service: DockerServiceProtocol) -> None:
    """
    The constructor for the LocalExecutionStrategy class.

    :param docker_service: The Docker service for container management.
    """

    self._docker_service = docker_service

cleanup

A method that performs any necessary cleanup.

Source code in dev_tool/services/execution/local.py
def cleanup(self) -> None:
    """A method that performs any necessary cleanup."""

ensure_database

A method that ensures the database container is available.

Parameters:

  • recreate (bool, default: False ) –

    Whether to recreate the database container.

Source code in dev_tool/services/execution/local.py
def ensure_database(self, recreate: bool = False) -> None:
    """
    A method that ensures the database container is available.

    :param recreate: Whether to recreate the database container.
    """

    self._docker_service.ensure_local_container(recreate=recreate)

run_bun_command

A method that executes a Bun command locally.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

Source code in dev_tool/services/execution/local.py
def run_bun_command(self, args: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
    """
    A method that executes a Bun command locally.

    :param args: The command arguments.
    :param kwargs: Additional subprocess arguments.
    :return: The completed process result.
    """

    command = ['bun', *args]

    check = kwargs.pop('check', False)
    return subprocess.run(command, **kwargs, check=check)

run_django_command

A method that executes a Django management command locally.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

Source code in dev_tool/services/execution/local.py
def run_django_command(self, args: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
    """
    A method that executes a Django management command locally.

    :param args: The command arguments.
    :param kwargs: Additional subprocess arguments.
    :return: The completed process result.
    """

    command = [VENV_PYTHON, BASE / 'manage.py', *args]

    check = kwargs.pop('check', False)
    return subprocess.run(command, **kwargs, check=check)

run_pip_command

A method that executes a uv pip command locally.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

Source code in dev_tool/services/execution/local.py
def run_pip_command(self, args: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
    """
    A method that executes a uv pip command locally.

    :param args: The command arguments.
    :param kwargs: Additional subprocess arguments.
    :return: The completed process result.
    """

    command = ['uv', 'pip', *args]

    check = kwargs.pop('check', False)
    return subprocess.run(command, **kwargs, check=check)

run_python_command

A method that executes a Python command locally.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

Source code in dev_tool/services/execution/local.py
def run_python_command(self, args: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
    """
    A method that executes a Python command locally.

    :param args: The command arguments.
    :param kwargs: Additional subprocess arguments.
    :return: The completed process result.
    """

    command = [VENV_PYTHON, *args]

    check = kwargs.pop('check', False)
    return subprocess.run(command, **kwargs, check=check)

run_seed

A method that runs the database seeding script locally.

Parameters:

  • seed_script (Path) –

    The path to the seed script.

Source code in dev_tool/services/execution/local.py
def run_seed(self, seed_script: Path) -> None:
    """
    A method that runs the database seeding script locally.

    :param seed_script: The path to the seed script.
    """

    command = [VENV_PYTHON, seed_script]
    subprocess.run(command, check=True)

run_server

A method that starts the Django development server locally.

Parameters:

  • ip_address (str) –

    The IP address to bind to.

  • port (int) –

    The port number to bind to.

Source code in dev_tool/services/execution/local.py
def run_server(self, ip_address: str, port: int) -> None:
    """
    A method that starts the Django development server locally.

    :param ip_address: The IP address to bind to.
    :param port: The port number to bind to.
    """

    from dev_tool.context import CONTEXT  # noqa: PLC0415
    from dev_tool.services.django.runner import DjangoServerRunner  # noqa: PLC0415

    project_name = CONTEXT.configuration.get_project_name()
    server = DjangoServerRunner(project_name=project_name, ip_address=ip_address, port=port)
    server.run_and_wait()

run_shell_script

A method that executes a Django shell script locally.

Parameters:

  • script (str) –

    The Python script to execute in Django shell.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

Source code in dev_tool/services/execution/local.py
def run_shell_script(self, script: str, **kwargs: Any) -> subprocess.CompletedProcess:
    """
    A method that executes a Django shell script locally.

    :param script: The Python script to execute in Django shell.
    :param kwargs: Additional subprocess arguments.
    :return: The completed process result.
    """

    command = [VENV_PYTHON, BASE / 'manage.py', 'shell', '-c', script]

    check = kwargs.pop('check', False)
    return subprocess.run(command, **kwargs, check=check)