Skip to content

config

dev_tool.config

__all__ = ['ConfigManager', 'ContainerPathDefault', 'DatabaseDefault', 'DevelopmentDefault', 'DockerConfig', 'DockerContainerDefault', 'DockerDefault', 'DockerFileDefault', 'DockerImageDefault', 'EnvConfig', 'FilesystemConfig', 'PyprojectConfig'] module-attribute

ContainerPathDefault

Default paths inside containers.

APP_ROOT = '/app' class-attribute instance-attribute

PARALLEL_ROOT = '/parallel' class-attribute instance-attribute

POSTGRES_DATA = '/var/lib/postgresql/data' class-attribute instance-attribute

DatabaseDefault

Default values for database configuration (generic PostgreSQL).

ENGINE = 'postgresql' class-attribute instance-attribute

HOST = 'localhost' class-attribute instance-attribute

NAME = 'postgres' class-attribute instance-attribute

PASSWORD = 'postgres' class-attribute instance-attribute

PORT = '5432' class-attribute instance-attribute

USER = 'postgres' class-attribute instance-attribute

DevelopmentDefault

Default values for local development environment.

DATABASE_NAME = 'stratus' class-attribute instance-attribute

DATABASE_PASSWORD = 'stratus' class-attribute instance-attribute

DATABASE_PORT = '5432' class-attribute instance-attribute

DATABASE_USER = 'stratus' class-attribute instance-attribute

DockerContainerDefault

Default Docker container naming conventions.

APP_SUFFIX = '-app' class-attribute instance-attribute

DB_SUFFIX = '-db' class-attribute instance-attribute

DockerDefault

Default values for Docker configuration.

APP_PORT = 8000 class-attribute instance-attribute

CONTAINER_PORT = 5432 class-attribute instance-attribute

CONTAINER_SIZE = '8g' class-attribute instance-attribute

POSTGRES_VERSION = '14' class-attribute instance-attribute

SSH_PORT = 2222 class-attribute instance-attribute

DockerFileDefault

Default Dockerfile and compose file names.

APP = 'Dockerfile.app' class-attribute instance-attribute

COMPOSE = 'docker-compose.yml' class-attribute instance-attribute

DB = 'Dockerfile.db' class-attribute instance-attribute

DockerImageDefault

Default Docker image names and tags.

APP = 'stratus:shared-app' class-attribute instance-attribute

CUSTOM = 'stratus:shared' class-attribute instance-attribute

DB = 'stratus:shared-db' class-attribute instance-attribute

DockerConfig

A class for managing Docker configuration settings.

This class provides methods for creating default Docker configurations based on environment variables and user settings.

The constructor for the DockerConfig class.

Source code in dev_tool/config/docker.py
def __init__(self) -> None:
    """The constructor for the DockerConfig class."""

    self._notification: NotificationProtocol | None = None
    self._resource_path_getter: Callable[[str], Path] | None = None

create_default_docker_config

A method that creates a default Docker configuration dictionary.

This method combines user-provided configuration with environment variables to create a complete Docker container configuration.

Parameters:

  • container_name (str) –

    The name to use for the Docker container.

  • docker_config (dict) –

    The user-provided Docker configuration dictionary.

Returns:

  • dict

    A complete Docker configuration dictionary.

Source code in dev_tool/config/docker.py
def create_default_docker_config(self, container_name: str, docker_config: dict) -> dict:
    """
    A method that creates a default Docker configuration dictionary.

    This method combines user-provided configuration with environment variables
    to create a complete Docker container configuration.

    :param container_name: The name to use for the Docker container.
    :param docker_config: The user-provided Docker configuration dictionary.
    :return: A complete Docker configuration dictionary.
    """

    version = docker_config.get('postgres-version', DockerDefault.POSTGRES_VERSION)
    host_port = os.getenv('DATABASE_PORT', DevelopmentDefault.DATABASE_PORT)
    container_port = DockerDefault.CONTAINER_PORT
    postgres_user = os.getenv('DATABASE_USER', DevelopmentDefault.DATABASE_USER)
    postgres_password = os.getenv('DATABASE_PASSWORD', DevelopmentDefault.DATABASE_PASSWORD)
    shm_size = docker_config.get('container-size', DockerDefault.CONTAINER_SIZE)

    return {
        'container_name': container_name,
        'container': f'postgres:{version}',
        'host_port': int(host_port),
        'container_port': int(container_port),
        'environment': {
            'POSTGRES_USER': postgres_user,
            'POSTGRES_PASSWORD': postgres_password,
        },
        'shm_size': shm_size,
        **{
            k: v
            for k, v in docker_config.items()
            if k not in ('postgres-version', 'container-size')
        },
    }

get_dockerfile_path

Get the Dockerfile path - project Dockerfile takes precedence over default.

Returns:

  • Path | None

    Path to Dockerfile to use, or None if using standard postgres image

Source code in dev_tool/config/docker.py
def get_dockerfile_path(self) -> Path | None:
    """
    Get the Dockerfile path - project Dockerfile takes precedence over default.

    :return: Path to Dockerfile to use, or None if using standard postgres image
    """

    project = BASE / DockerFileDefault.DB

    if project.exists():
        return project

    if self._resource_path_getter is not None:
        default = self._resource_path_getter(f'templates/docker/{DockerFileDefault.DB}')

        if default.exists():
            return default

    return None

set_notification

A method that sets the notification service.

Parameters:

Source code in dev_tool/config/docker.py
def set_notification(self, notification: NotificationProtocol) -> None:
    """
    A method that sets the notification service.

    :param notification: The notification service to use.
    """

    self._notification = notification

set_resource_path_getter

A method that sets the resource path getter function.

Parameters:

  • getter (Callable[[str], Path]) –

    A callable that takes a path string and returns an absolute Path.

Source code in dev_tool/config/docker.py
def set_resource_path_getter(self, getter: Callable[[str], Path]) -> None:
    """
    A method that sets the resource path getter function.

    :param getter: A callable that takes a path string and returns an absolute Path.
    """

    self._resource_path_getter = getter

should_build_custom_image

Determine if we should build a custom image.

Returns:

  • bool

    True if we should build custom image

Source code in dev_tool/config/docker.py
def should_build_custom_image(self) -> bool:
    """
    Determine if we should build a custom image.

    :return: True if we should build custom image
    """

    return self.get_dockerfile_path() is not None

EnvConfig

A class for managing environment configuration.

This class provides methods for loading, reloading, and creating default environment variable configurations.

create_default_env

A method that creates a default environment file.

This method copies the content from a template file to create a new environment configuration file if it doesn't already exist.

Parameters:

  • path (Path) –

    The path where the new environment file should be created.

  • template (Path) –

    The path to the template environment file.

Source code in dev_tool/config/env.py
def create_default_env(self, path: Path, template: Path) -> None:
    """
    A method that creates a default environment file.

    This method copies the content from a template file to create a new
    environment configuration file if it doesn't already exist.

    :param path: The path where the new environment file should be created.
    :param template: The path to the template environment file.
    """

    if path.exists():
        return

    if not template.exists():
        return

    with template.open('r', encoding='utf-8') as handle:
        content = handle.read()

    with path.open('w', encoding='utf-8') as handle:
        handle.write(content)

get_docker_authorization

A method that retrieves Docker authorization credentials.

This method gets the username and password for Docker from environment variables, falling back to default values if not set.

Returns:

  • tuple[str, str]

    A tuple containing (username, password).

Raises:

  • OSError

    If the username or password is empty.

Source code in dev_tool/config/env.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,
    falling back to default values if not set.

    :return: A tuple containing (username, password).
    :raises OSError: If the username or password is empty.
    """

    username = os.getenv('DATABASE_USER', DevelopmentDefault.DATABASE_USER)
    password = os.getenv('DATABASE_PASSWORD', DevelopmentDefault.DATABASE_PASSWORD)

    if not username or not password:
        message = 'DATABASE_USER and DATABASE_PASSWORD must be set in the environment.'
        raise OSError(message)

    return username, password

reload

A method that reloads environment variables from a .env file.

This method loads environment variables from the specified file path, overriding any existing variables with the same names.

Parameters:

  • dotenv_path (Path | str | None, default: None ) –

    The path to the .env file to load.

  • prompt (bool, default: False ) –

    Whether to prompt the user for the env file path.

Source code in dev_tool/config/env.py
def reload(self, dotenv_path: Path | str | None = None, prompt: bool = False) -> None:
    """
    A method that reloads environment variables from a .env file.

    This method loads environment variables from the specified file path,
    overriding any existing variables with the same names.

    :param dotenv_path: The path to the .env file to load.
    :param prompt: Whether to prompt the user for the env file path.
    """

    if dotenv_path is None:
        dotenv_path = DEVELOPMENT_ENV

    if prompt:
        dotenv_path = (
            input('Which .env file do you want to use? (default: "development.env"): ') or
            'development.env'
        )

    if isinstance(dotenv_path, str):
        dotenv_path = Path(dotenv_path)

    if dotenv_path.exists():
        load_dotenv(dotenv_path=dotenv_path, override=True)
        self._setup_parallel_development()

FilesystemConfig

A class for handling filesystem operations for configuration.

This class provides methods for resolving paths and reading configuration files.

get_resource_path

A method that resolves a resource path.

This method handles both packaged (frozen) and development environments by resolving the appropriate absolute path to a resource.

Parameters:

  • path (str) –

    The relative path to the resource.

Returns:

  • Path

    The absolute Path to the resource.

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

    This method handles both packaged (frozen) and development environments
    by resolving the appropriate absolute path to a resource.

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

    if hasattr(sys, '_MEIPASS'):
        return Path(sys._MEIPASS, path)

    return Path(__file__).parent.parent.parent / path

get_developer_token

A method that retrieves a developer token from a file.

This method reads a token from the specified file, stripping any whitespace.

Parameters:

  • path (Path) –

    The path to the file containing the token.

Returns:

  • str | None

    The token as a string, or None if the file doesn't exist.

Source code in dev_tool/config/filesystem.py
def get_developer_token(self, path: Path) -> str | None:
    """
    A method that retrieves a developer token from a file.

    This method reads a token from the specified file, stripping any whitespace.

    :param path: The path to the file containing the token.
    :return: The token as a string, or None if the file doesn't exist.
    """

    if not path.exists():
        return None

    with open(path, 'r', encoding='utf-8') as handle:
        return handle.read().strip()

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: dict[ConfigEvent, list[Callable]] = {
        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

    assert isinstance(cls._instance, cls)
    return cls._instance

set_notification classmethod

A class method that sets the notification service for the config manager.

Parameters:

Source code in dev_tool/config/manager.py
@classmethod
def set_notification(cls, notification: NotificationProtocol) -> None:
    """
    A class method that sets the notification service for the config manager.

    :param notification: The notification service to use.
    """

    cls._notification = notification

    if cls._instance is not None:
        cls._instance.docker.set_notification(notification)
        cls._instance.docker.set_resource_path_getter(cls._instance.fs.get_resource_path)
        cls._instance.pyproject.set_notification(notification)

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_bun_config

A method that retrieves the Bun configuration.

This method gets the Bun configuration section.

Returns:

  • dict[str, Any]

    The Bun configuration as a dictionary.

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

    This method gets the Bun configuration section.

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

    return self.pyproject.get_bun_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_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_dev_tool_config

A method that retrieves the dev_tool configuration.

This method gets the 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 dev_tool configuration section.

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

    return self.pyproject.get_dev_tool_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 developer 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 developer token string, or None if not available.
    """

    return self.fs.get_developer_token(DEVELOPER_TOKEN)

get_django_config

A method that retrieves the Django configuration.

This method gets the Django configuration section.

Returns:

  • dict[str, Any]

    The Django configuration as a dictionary.

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

    This method gets the Django configuration section.

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

    return self.pyproject.get_django_config()

get_django_coverage_config

A method that retrieves the Django coverage configuration.

This method gets the Django coverage configuration section.

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 coverage configuration section.

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

    return self.pyproject.get_django_coverage_config()

get_django_unittest_config

A method that retrieves the Django unit test configuration.

This method gets the Django unit test configuration section.

Returns:

  • dict[str, Any]

    The Django unit test 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 unit test configuration.

    This method gets the Django unit test configuration section.

    :return: The Django unit test configuration as a dictionary.
    """

    return self.pyproject.get_django_unittest_config()

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()

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_project_name

A method that retrieves the project name.

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

Returns:

  • str

    The project name 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 file.

    :return: The project name string.
    """

    return self.pyproject.get_project_name()

get_python_coverage_config

A method that retrieves the Python coverage configuration.

This method gets the Python coverage configuration section.

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 coverage configuration section.

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

    return self.pyproject.get_python_coverage_config()

get_python_unittest_config

A method that retrieves the Python unittest configuration.

This method gets the Python unittest configuration section.

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 unittest configuration section.

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

    return self.pyproject.get_python_unittest_config()

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_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_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_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_version

A method that retrieves the current version.

Returns:

  • str

    The version string.

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

    :return: The version string.
    """

    return __version__

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)

register_listener

A method that registers a callback for configuration change events.

Parameters:

  • event (ConfigEvent) –

    The configuration event to listen for.

  • callback (Callable) –

    The callback function to invoke when the event occurs.

Source code in dev_tool/config/manager.py
def register_listener(self, event: ConfigEvent, callback: Callable) -> None:
    """
    A method that registers a callback for configuration change events.

    :param event: The configuration event to listen for.
    :param callback: The callback function to invoke when the event occurs.
    """

    if event in self._listener:
        self._listener[event].append(callback)

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(DEVELOPMENT_ENV)

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)

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:
        message = 'Unable to initialize the file watcher'
        self._notify_warning(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()

unregister_listener

A method that unregisters a callback for configuration change events.

Parameters:

  • event (ConfigEvent) –

    The configuration event to stop listening for.

  • callback (Callable) –

    The callback function to remove.

Source code in dev_tool/config/manager.py
def unregister_listener(self, event: ConfigEvent, callback: Callable) -> None:
    """
    A method that unregisters a callback for configuration change events.

    :param event: The configuration event to stop listening for.
    :param callback: The callback function to remove.
    """

    if event in self._listener and callback in self._listener[event]:
        self._listener[event].remove(callback)

validate_configuration

A method that validates that required configuration files exist.

This method emits warnings for any missing configuration files.

Source code in dev_tool/config/manager.py
def validate_configuration(self) -> None:
    """
    A method that validates that required configuration files exist.

    This method emits warnings for any missing configuration files.
    """

    if not PYPROJECT.exists():
        message = f'"{PYPROJECT.name}" does not exist. Please create one for this project.'
        emit_warning(message)

        log.debug(message)

    if not DEVELOPMENT_ENV.exists():
        message = f'"{DEVELOPMENT_ENV.name}" does not exist. Please create one for this project.'
        emit_warning(message)

        log.debug(message)

PyprojectConfig

A class for managing pyproject.toml configuration.

This class provides methods for loading, parsing, and retrieving settings from the pyproject.toml file.

The constructor for the PyprojectConfig class.

This method initializes an empty configuration dictionary.

Source code in dev_tool/config/pyproject.py
def __init__(self) -> None:
    """
    The constructor for the PyprojectConfig class.

    This method initializes an empty configuration dictionary.
    """

    self._notification: NotificationProtocol | None = None
    self._pyproject: dict[str, Any] = {}

create_default

A method that creates a default pyproject.toml file.

This method copies the content from a template file to create a new pyproject.toml file if it doesn't already exist.

Parameters:

  • path (Path) –

    The path where the new file should be created.

  • template (Path) –

    The path to the template file.

Source code in dev_tool/config/pyproject.py
def create_default(self, path: Path, template: Path) -> None:
    """
    A method that creates a default pyproject.toml file.

    This method copies the content from a template file to create a new
    pyproject.toml file if it doesn't already exist.

    :param path: The path where the new file should be created.
    :param template: The path to the template file.
    """

    if path.exists():
        return

    if not template.exists():
        return

    with template.open('r', encoding='utf-8') as handle:
        content = handle.read()

    with path.open('w', encoding='utf-8') as handle:
        handle.write(content)

    self.reload(path)

get_bun_config

A method that retrieves the Bun configuration.

This method gets the Bun configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The Bun configuration as a dictionary.

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

    This method gets the Bun configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('bun', {})

get_coverage_config

A method that retrieves the coverage configuration.

This method gets the coverage configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The coverage configuration as a dictionary.

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

    This method gets the coverage configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('coverage', {})

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/pyproject.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.get_tool_config('dev_tool')

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/pyproject.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.
    """

    config = self.get_dev_tool_config()
    return config.get('port')

get_django_config

A method that retrieves the Django configuration.

This method gets the Django configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The Django configuration as a dictionary.

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

    This method gets the Django configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('django', {})

get_django_coverage_config

A method that retrieves the Django coverage configuration.

This method gets the Django-specific coverage configuration and merges it with the base.

Returns:

  • dict[str, Any]

    The merged Django coverage configuration as a dictionary.

Source code in dev_tool/config/pyproject.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 and merges it with the base.

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

    base = self.get_coverage_config()
    django_config = self._get_nested_config(self.get_dev_tool_config(), 'coverage', 'django', default={})
    return {**base, **django_config}

get_django_unittest_config

A method that retrieves the Django unittest configuration.

This method gets the Django-specific unittest configuration and merges it with the base.

Returns:

  • dict[str, Any]

    The merged Django unittest configuration as a dictionary.

Source code in dev_tool/config/pyproject.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 and merges it with the base.

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

    base = self.get_unittest_config()
    django_config = self._get_nested_config(self.get_dev_tool_config(), 'unittest', 'django', default={})
    return {**base, **django_config}

get_docker_config

A method that retrieves the Docker configuration.

This method gets the Docker configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The Docker configuration as a dictionary.

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

    This method gets the Docker configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('docker', {})

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/pyproject.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.
    """

    project_config = self.get_value('project', default={})
    return project_config.get(key, {}) if isinstance(project_config, dict) else {}

get_project_name

A method that retrieves the project name.

This method gets the project name from the configuration.

Returns:

  • str

    The project name, or 'project' if not specified.

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

    This method gets the project name from the configuration.

    :return: The project name, or 'project' if not specified.
    """

    return self.get_value('project', 'name', default='project')

get_python_coverage_config

A method that retrieves the Python coverage configuration.

This method gets the Python-specific coverage configuration and merges it with the base.

Returns:

  • dict[str, Any]

    The merged Python coverage configuration as a dictionary.

Source code in dev_tool/config/pyproject.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 and merges it with the base.

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

    base = self.get_coverage_config()
    python_config = self._get_nested_config(self.get_dev_tool_config(), 'coverage', 'python', default={})
    return {**base, **python_config}

get_python_unittest_config

A method that retrieves the Python unittest configuration.

This method gets the Python-specific unittest configuration and merges it with the base.

Returns:

  • dict[str, Any]

    The merged Python unittest configuration as a dictionary.

Source code in dev_tool/config/pyproject.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 and merges it with the base.

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

    base = self.get_unittest_config()
    python_config = self._get_nested_config(self.get_dev_tool_config(), 'unittest', 'python', default={})
    return {**base, **python_config}

get_scripting_config

A method that retrieves the scripting configuration.

This method gets the scripting configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The scripting configuration as a dictionary.

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

    This method gets the scripting configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('scripting', {})

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/pyproject.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.
    """

    tool_config = self.get_value('tool', default={})
    return tool_config.get(key, {}) if isinstance(tool_config, dict) else {}

get_unittest_config

A method that retrieves the unittest configuration.

This method gets the unittest configuration section from dev_tool config.

Returns:

  • dict[str, Any]

    The unittest configuration as a dictionary.

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

    This method gets the unittest configuration section from dev_tool config.

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

    return self.get_dev_tool_config().get('unittest', {})

get_value

A method that retrieves a value from the pyproject.toml configuration.

This method traverses the configuration using the provided keys and returns the default value if the path doesn't exist.

Parameters:

  • keys (str, default: () ) –

    The sequence of keys to navigate through.

  • default (Any, default: None ) –

    The default value to return if the path doesn't exist.

Returns:

  • Any

    The value at the specified path, or the default.

Source code in dev_tool/config/pyproject.py
def get_value(self, *keys: str, default: Any = None) -> Any:
    """
    A method that retrieves a value from the pyproject.toml configuration.

    This method traverses the configuration using the provided keys
    and returns the default value if the path doesn't exist.

    :param keys: The sequence of keys to navigate through.
    :param default: The default value to return if the path doesn't exist.
    :return: The value at the specified path, or the default.
    """

    value = self._pyproject

    for key in keys:
        if not isinstance(value, dict) or key not in value:
            return default

        value = value[key]

    return value

reload

A method that reloads the pyproject.toml configuration.

This method reads the configuration from the specified file path and updates the internal configuration dictionary.

Parameters:

  • path (Path) –

    The path to the pyproject.toml file.

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

    This method reads the configuration from the specified file path
    and updates the internal configuration dictionary.

    :param path: The path to the pyproject.toml file.
    """

    if path.exists():
        with open(path, 'rb') as handle:
            self._pyproject = tomllib.load(handle)
    else:
        self._pyproject = {}

        message = f'{path} does not exist'
        self._notify_normal(message)
        log.debug(message)

set_notification

A method that sets the notification service.

Parameters:

Source code in dev_tool/config/pyproject.py
def set_notification(self, notification: NotificationProtocol) -> None:
    """
    A method that sets the notification service.

    :param notification: The notification service to use.
    """

    self._notification = notification