Skip to content

provider

dev_tool.services.execution.provider

ExecutionStrategyProvider

A provider class for managing the singleton ExecutionStrategy instance.

This class centralizes strategy creation to avoid duplicate logic scattered across multiple services.

configure classmethod

A method that configures the provider with required dependencies.

Parameters:

Source code in dev_tool/services/execution/provider.py
@classmethod
def configure(cls, docker_service: DockerServiceProtocol) -> None:
    """
    A method that configures the provider with required dependencies.

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

    cls._docker_service = docker_service

get classmethod

A method that returns the singleton ExecutionStrategy instance.

Returns:

Source code in dev_tool/services/execution/provider.py
@classmethod
def get(cls) -> ExecutionStrategy:
    """
    A method that returns the singleton ExecutionStrategy instance.

    :return: The ExecutionStrategy instance.
    """

    if cls._instance is None:
        from dev_tool.context import CONTEXT  # noqa: PLC0415
        from dev_tool.services.execution.containerized import ContainerizedExecutionStrategy  # noqa: PLC0415
        from dev_tool.services.execution.local import LocalExecutionStrategy  # noqa: PLC0415

        containerized = CONTEXT.configuration.pyproject.get_dev_tool_config().get('containerized', False)

        if containerized:
            cls._instance = ContainerizedExecutionStrategy(
                configuration=CONTEXT.configuration,
                project_name=CONTEXT.configuration.get_project_name()
            )
        else:
            if cls._docker_service is None:
                message = 'ExecutionStrategyProvider not configured. Call configure() first.'
                raise RuntimeError(message)

            cls._instance = LocalExecutionStrategy(
                docker_service=cls._docker_service
            )

    return cls._instance

is_containerized classmethod

A method that checks if the current strategy is containerized.

Returns:

  • bool

    True if containerized, False otherwise.

Source code in dev_tool/services/execution/provider.py
@classmethod
def is_containerized(cls) -> bool:
    """
    A method that checks if the current strategy is containerized.

    :return: True if containerized, False otherwise.
    """

    from dev_tool.context import CONTEXT  # noqa: PLC0415

    return CONTEXT.configuration.pyproject.get_dev_tool_config().get('containerized', False)

reset classmethod

A method that resets the singleton instance.

Source code in dev_tool/services/execution/provider.py
@classmethod
def reset(cls) -> None:
    """A method that resets the singleton instance."""

    cls._instance = None