Skip to content

service

dev_tool.services.command.service

log = logging.getLogger(__name__) module-attribute

CommandRunner

Bases: BaseService

A service that abstracts command execution for local or containerized environments.

The constructor for the CommandRunner class.

Parameters:

Source code in dev_tool/services/command/service.py
def __init__(self, execution_strategy: ExecutionStrategyProtocol) -> None:
    """
    The constructor for the CommandRunner class.

    :param execution_strategy: The execution strategy for running commands.
    """

    super().__init__()

    self._execution_strategy = execution_strategy

execution_strategy property

A property that returns the ExecutionStrategy.

Returns:

cleanup_build_context

A method that cleans up temporary build context directories.

Source code in dev_tool/services/command/service.py
def cleanup_build_context(self) -> None:
    """A method that cleans up temporary build context directories."""

    self.execution_strategy.cleanup()

ensure_services

A method that ensures Docker services are running.

Source code in dev_tool/services/command/service.py
def ensure_services(self) -> None:
    """A method that ensures Docker services are running."""

    self.execution_strategy.ensure_database(recreate=False)

is_containerized_available

A method that checks if Docker and docker-compose are available.

Returns:

  • bool

    True if Docker is available, False otherwise.

Source code in dev_tool/services/command/service.py
def is_containerized_available(self) -> bool:
    """
    A method that checks if Docker and docker-compose are available.

    :return: True if Docker is available, False otherwise.
    """

    try:
        command = ['docker', '--version']
        subprocess.run(command, capture_output=True, check=True)

        command = ['docker', 'compose', 'version']
        subprocess.run(command, capture_output=True, check=True)
    except Exception:
        return False
    else:
        return True

run_bun_command

A method that executes a Bun command.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

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

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

    return self.execution_strategy.run_bun_command(args, **kwargs)

run_django_command

A method that executes a Django management command.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

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

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

    return self.execution_strategy.run_django_command(args, **kwargs)

run_pip_command

A method that executes a pip command.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

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

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

    return self.execution_strategy.run_pip_command(args, **kwargs)

run_python_command

A method that executes a Python command.

Parameters:

  • args (list[str]) –

    The command arguments.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

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

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

    return self.execution_strategy.run_python_command(args, **kwargs)

run_shell_script

A method that executes a Django shell script.

Parameters:

  • script (str) –

    The Python script to execute in Django shell.

  • kwargs (Any, default: {} ) –

    Additional subprocess arguments.

Returns:

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

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

    return self.execution_strategy.run_shell_script(script, **kwargs)