Skip to content

manager

dev_tool.config.manager

log = logging.getLogger(__name__) module-attribute

ConfigEvent

Bases: Enum

An enumeration of configuration change event types.

This enum defines the types of configuration events that can trigger callbacks.

ENV = auto() class-attribute instance-attribute

PYPROJECT = auto() class-attribute instance-attribute

ConfigManager

A singleton class for managing configuration across the application.

This class handles loading, reloading, and providing access to various configuration settings from different sources.

A constructor for the ConfigManager class.

This method initializes all configuration components and sets up file watching if a watcher is provided.

Parameters:

  • watcher (FileWatcherService | None, default: None ) –

    An optional file watcher service for monitoring config changes.

Source code in dev_tool/config/manager.py
def __init__(self, watcher: FileWatcherService | None = None) -> None:
    """
    A constructor for the ConfigManager class.

    This method initializes all configuration components and sets up
    file watching if a watcher is provided.

    :param watcher: An optional file watcher service for monitoring config changes.
    """

    if getattr(self, '_initialized', False):
        return

    self._initialized = True

    self.docker = DockerConfig()
    self.env = EnvConfig()
    self.fs = FilesystemConfig()
    self.pyproject = PyprojectConfig()

    self._listener = {
        ConfigEvent.ENV: [],
        ConfigEvent.PYPROJECT: []
    }

    self._watcher = watcher
    self.reload_all()

docker = DockerConfig() instance-attribute

env = EnvConfig() instance-attribute

fs = FilesystemConfig() instance-attribute

pyproject = PyprojectConfig() instance-attribute

__new__

The method that implements the singleton pattern.

This method ensures only one instance of ConfigManager exists.

Returns:

  • Self

    The singleton ConfigManager instance.

Source code in dev_tool/config/manager.py
def __new__(cls) -> Self:
    """
    The method that implements the singleton pattern.

    This method ensures only one instance of ConfigManager exists.

    :return: The singleton ConfigManager instance.
    """

    if cls._instance is None:
        cls._instance = super().__new__(cls)
        cls._instance._initialized = False

    return cls._instance

initialize_watcher

A method that initializes the file watcher.

This method sets up file watching for configuration files with the specified polling interval.

Parameters:

  • interval (float, default: 1.0 ) –

    The polling interval in seconds.

Source code in dev_tool/config/manager.py
def initialize_watcher(self, interval: float = 1.0) -> None:
    """
    A method that initializes the file watcher.

    This method sets up file watching for configuration files with
    the specified polling interval.

    :param interval: The polling interval in seconds.
    """

    if self._watcher is None:
        self._watcher = FileWatcherService(interval=interval)
        self._watcher.watch(DEVELOPMENT_ENV, self._on_env_changed)
        self._watcher.watch(PYPROJECT, self._on_pyproject_changed)

start_watching

A method that starts the file watcher.

This method begins monitoring configuration files for changes.

Source code in dev_tool/config/manager.py
def start_watching(self) -> None:
    """
    A method that starts the file watcher.

    This method begins monitoring configuration files for changes.
    """

    if self._watcher:
        self._watcher.start()
    else:
        from dev_tool.context import CONTEXT  # noqa: PLC0415

        message = 'Unable to initialize the file watcher'
        CONTEXT.notification.warning_text(message)

        log.debug(message)

stop_watching

A method that stops the file watcher.

This method ends monitoring of configuration files.

Source code in dev_tool/config/manager.py
def stop_watching(self) -> None:
    """
    A method that stops the file watcher.

    This method ends monitoring of configuration files.
    """

    if self._watcher:
        self._watcher.stop()

reload_all

A method that reloads all configuration files.

This method refreshes both environment and pyproject configurations.

Source code in dev_tool/config/manager.py
def reload_all(self) -> None:
    """
    A method that reloads all configuration files.

    This method refreshes both environment and pyproject configurations.
    """

    self.reload_env()
    self.reload_pyproject()

reload_env

A method that reloads environment variables.

This method refreshes environment variables from the .env file.

Source code in dev_tool/config/manager.py
def reload_env(self) -> None:
    """
    A method that reloads environment variables.

    This method refreshes environment variables from the .env file.
    """

    self.env.reload()

reload_pyproject

A method that reloads the pyproject.toml configuration.

This method refreshes configuration from the pyproject.toml file.

Source code in dev_tool/config/manager.py
def reload_pyproject(self) -> None:
    """
    A method that reloads the pyproject.toml configuration.

    This method refreshes configuration from the pyproject.toml file.
    """

    self.pyproject.reload(PYPROJECT)

create_default_development_env

A method that creates a default development.env file.

This method creates the development environment file from a template.

Source code in dev_tool/config/manager.py
def create_default_development_env(self) -> None:
    """
    A method that creates a default development.env file.

    This method creates the development environment file from a template.
    """

    path = self.fs.get_resource_path('templates/project/development.env')
    self.env.create_default_env(DEVELOPMENT_ENV, path)

create_default_pyproject

A method that creates a default pyproject.toml file.

This method creates the pyproject.toml file from a template.

Source code in dev_tool/config/manager.py
def create_default_pyproject(self) -> None:
    """
    A method that creates a default pyproject.toml file.

    This method creates the pyproject.toml file from a template.
    """

    path = self.fs.get_resource_path('templates/project/pyproject.toml')
    self.pyproject.create_default(PYPROJECT, path)

get_resource_path

A method that resolves a resource path.

This method delegates to the filesystem configuration to resolve paths.

Parameters:

  • path (str) –

    The relative path to the resource.

Returns:

  • Path

    The absolute Path to the resource.

Source code in dev_tool/config/manager.py
def get_resource_path(self, path: str) -> Path:
    """
    A method that resolves a resource path.

    This method delegates to the filesystem configuration to resolve paths.

    :param path: The relative path to the resource.
    :return: The absolute Path to the resource.
    """

    return self.fs.get_resource_path(path)

get_project_name

A method that retrieves the project name.

This method gets the project name from the pyproject.toml configuration.

Returns:

  • str

    The project name as a string.

Source code in dev_tool/config/manager.py
def get_project_name(self) -> str:
    """
    A method that retrieves the project name.

    This method gets the project name from the pyproject.toml configuration.

    :return: The project name as a string.
    """

    return self.pyproject.get_project_name()

get_current_version

A method that retrieves the current version.

This method returns the current version of the application.

Returns:

  • str

    The version string.

Source code in dev_tool/config/manager.py
def get_current_version(self) -> str:
    """
    A method that retrieves the current version.

    This method returns the current version of the application.

    :return: The version string.
    """

    return __version__

get_project_config

A method that retrieves a project configuration section.

This method gets a specific section from the project configuration.

Parameters:

  • key (str) –

    The section key to retrieve.

Returns:

  • dict[str, Any]

    The configuration section as a dictionary.

Source code in dev_tool/config/manager.py
def get_project_config(self, key: str) -> dict[str, Any]:
    """
    A method that retrieves a project configuration section.

    This method gets a specific section from the project configuration.

    :param key: The section key to retrieve.
    :return: The configuration section as a dictionary.
    """

    return self.pyproject.get_project_config(key)

get_tool_config

A method that retrieves a tool configuration section.

This method gets a specific section from the tool configuration.

Parameters:

  • key (str) –

    The section key to retrieve.

Returns:

  • dict[str, Any]

    The configuration section as a dictionary.

Source code in dev_tool/config/manager.py
def get_tool_config(self, key: str) -> dict[str, Any]:
    """
    A method that retrieves a tool configuration section.

    This method gets a specific section from the tool configuration.

    :param key: The section key to retrieve.
    :return: The configuration section as a dictionary.
    """

    return self.pyproject.get_tool_config(key)

get_dev_tool_config

A method that retrieves the dev_tool configuration.

This method gets the entire dev_tool configuration section.

Returns:

  • dict[str, Any]

    The dev_tool configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_dev_tool_config(self) -> dict[str, Any]:
    """
    A method that retrieves the dev_tool configuration.

    This method gets the entire dev_tool configuration section.

    :return: The dev_tool configuration as a dictionary.
    """

    return self.pyproject.get_dev_tool_config()

get_coverage_config

A method that retrieves the coverage configuration.

This method gets the coverage configuration section.

Returns:

  • dict[str, Any]

    The coverage configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_coverage_config(self) -> dict[str, Any]:
    """
    A method that retrieves the coverage configuration.

    This method gets the coverage configuration section.

    :return: The coverage configuration as a dictionary.
    """

    return self.pyproject.get_coverage_config()

get_django_coverage_config

A method that retrieves the Django coverage configuration.

This method gets the Django-specific coverage configuration merged with the base.

Returns:

  • dict[str, Any]

    The Django coverage configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_django_coverage_config(self) -> dict[str, Any]:
    """
    A method that retrieves the Django coverage configuration.

    This method gets the Django-specific coverage configuration merged with the base.

    :return: The Django coverage configuration as a dictionary.
    """

    return self.pyproject.get_django_coverage_config()

get_python_coverage_config

A method that retrieves the Python coverage configuration.

This method gets the Python-specific coverage configuration merged with the base.

Returns:

  • dict[str, Any]

    The Python coverage configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_python_coverage_config(self) -> dict[str, Any]:
    """
    A method that retrieves the Python coverage configuration.

    This method gets the Python-specific coverage configuration merged with the base.

    :return: The Python coverage configuration as a dictionary.
    """

    return self.pyproject.get_python_coverage_config()

get_dev_tool_port

A method that retrieves the dev_tool port setting.

This method gets the port number configured for the dev_tool.

Returns:

  • str | None

    The port string, or None if not configured.

Source code in dev_tool/config/manager.py
def get_dev_tool_port(self) -> str | None:
    """
    A method that retrieves the dev_tool port setting.

    This method gets the port number configured for the dev_tool.

    :return: The port string, or None if not configured.
    """

    return self.pyproject.get_dev_tool_port()

get_developer_token

A method that retrieves the developer token.

This method gets the developer token from the token file.

Returns:

  • str | None

    The token string, or None if not available.

Source code in dev_tool/config/manager.py
def get_developer_token(self) -> str | None:
    """
    A method that retrieves the developer token.

    This method gets the developer token from the token file.

    :return: The token string, or None if not available.
    """

    return self.fs.get_developer_token(DEVELOPER_TOKEN)

get_docker_authorization

A method that retrieves Docker authorization credentials.

This method gets the username and password for Docker from environment variables.

Returns:

  • tuple[str, str]

    A tuple containing (username, password).

Source code in dev_tool/config/manager.py
def get_docker_authorization(self) -> tuple[str, str]:
    """
    A method that retrieves Docker authorization credentials.

    This method gets the username and password for Docker from environment variables.

    :return: A tuple containing (username, password).
    """

    return self.env.get_docker_authorization()

get_docker_config

A method that retrieves the Docker configuration.

This method gets the Docker configuration section.

Returns:

  • dict[str, Any]

    The Docker configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_docker_config(self) -> dict[str, Any]:
    """
    A method that retrieves the Docker configuration.

    This method gets the Docker configuration section.

    :return: The Docker configuration as a dictionary.
    """

    return self.pyproject.get_docker_config()

create_default_docker_config

A method that creates a default Docker configuration.

This method generates a complete Docker configuration using the project name and user-provided Docker configuration.

Returns:

  • dict[str, Any]

    A complete Docker configuration dictionary.

Source code in dev_tool/config/manager.py
def create_default_docker_config(self) -> dict[str, Any]:
    """
    A method that creates a default Docker configuration.

    This method generates a complete Docker configuration using the project name
    and user-provided Docker configuration.

    :return: A complete Docker configuration dictionary.
    """

    return self.docker.create_default_docker_config(
        self.get_project_name(),
        self.get_docker_config()
    )

get_scripting_config

A method that retrieves the scripting configuration.

This method gets the scripting configuration section.

Returns:

  • dict[str, Any]

    The scripting configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_scripting_config(self) -> dict[str, Any]:
    """
    A method that retrieves the scripting configuration.

    This method gets the scripting configuration section.

    :return: The scripting configuration as a dictionary.
    """

    return self.pyproject.get_scripting_config()

get_unittest_config

A method that retrieves the unittest configuration.

This method gets the unittest configuration section.

Returns:

  • dict[str, Any]

    The unittest configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_unittest_config(self) -> dict[str, Any]:
    """
    A method that retrieves the unittest configuration.

    This method gets the unittest configuration section.

    :return: The unittest configuration as a dictionary.
    """

    return self.pyproject.get_unittest_config()

get_django_unittest_config

A method that retrieves the Django unittest configuration.

This method gets the Django-specific unittest configuration merged with the base.

Returns:

  • dict[str, Any]

    The Django unittest configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_django_unittest_config(self) -> dict[str, Any]:
    """
    A method that retrieves the Django unittest configuration.

    This method gets the Django-specific unittest configuration merged with the base.

    :return: The Django unittest configuration as a dictionary.
    """

    return self.pyproject.get_django_unittest_config()

get_python_unittest_config

A method that retrieves the Python unittest configuration.

This method gets the Python-specific unittest configuration merged with the base.

Returns:

  • dict[str, Any]

    The Python unittest configuration as a dictionary.

Source code in dev_tool/config/manager.py
def get_python_unittest_config(self) -> dict[str, Any]:
    """
    A method that retrieves the Python unittest configuration.

    This method gets the Python-specific unittest configuration merged with the base.

    :return: The Python unittest configuration as a dictionary.
    """

    return self.pyproject.get_python_unittest_config()