harp.config.builders¶
- class ConfigurationBuilder[source]¶
Bases:
ConfigurationBuilder
A builder class for assembling the global configuration settings for HARP from various sources.
This class extends config.ConfigurationBuilder, incorporating additional functionality specific to HARP, such as handling default applications and integrating with the ApplicationsRegistry. It supports adding configuration from files, environment variables, and direct values, with a focus on flexibility and ease of use.
- Attributes:
_defaults (dict): Default values for the configuration, typically loaded from internal defaults or specified by the user. applications (ApplicationsRegistryType): An instance of ApplicationsRegistry or a subclass, managing the registration and configuration of HARP applications.
- Methods:
add_file(filename: str): Adds a single configuration file by its filename. add_files(filenames: Iterable[str]): Adds multiple configuration files by their filenames. add_values(values: dict): Adds configuration values directly from a dictionary. normalize(x: dict): Normalizes the configuration values, potentially transforming them based on application-specific logic. build() -> GlobalSettings: Constructs the final, aggregated configuration settings as a GlobalSettings instance. from_commandline_options(options): Class method to create an instance of ConfigurationBuilder from command line options. from_bytes(serialized: bytes, **kwargs) -> Self: Class method to create an instance of ConfigurationBuilder from serialized bytes.
The ConfigurationBuilder is central to the dynamic configuration system in HARP, allowing configurations to be built and modified in a flexible and intuitive manner.
Initializes a new instance of the ConfigurationBuilder.
- Parameters:
default_values (dict, optional): A dictionary of default configuration values. Defaults to None. use_default_applications (bool, optional): Whether to automatically include default HARP applications in the configuration. Defaults to True. ApplicationsRegistryType (type, optional): The class to use for the applications registry. Defaults to ApplicationsRegistry.
- __init__(default_values=None, /, *, use_default_applications=True, ApplicationsRegistryType=<class 'harp.config.applications.ApplicationsRegistry'>)[source]¶
Initializes a new instance of the ConfigurationBuilder.
- Parameters:
default_values (dict, optional): A dictionary of default configuration values. Defaults to None. use_default_applications (bool, optional): Whether to automatically include default HARP applications in the configuration. Defaults to True. ApplicationsRegistryType (type, optional): The class to use for the applications registry. Defaults to ApplicationsRegistry.
- Return type:
None
- add_file(filename)[source]¶
Adds a configuration file to the builder.
- Parameters:
filename (str): The path to the configuration file to add.
- Raises:
ValueError: If the file extension is not recognized.
- Parameters:
filename (str)
- add_files(filenames)[source]¶
Adds multiple configuration files to the builder.
- Parameters:
filenames (Iterable[str]): An iterable of file paths to add.
- add_values(values)[source]¶
Adds configuration values directly from a dictionary.
- Parameters:
values (dict): A dictionary of configuration values to add.
- Parameters:
values (dict)
- build()[source]¶
Constructs the final, aggregated configuration settings as a GlobalSettings instance.
- Returns:
GlobalSettings: The aggregated global settings derived from all added sources.
- Return type:
- classmethod from_bytes(serialized, **kwargs)[source]¶
Creates an instance of ConfigurationBuilder from serialized bytes.
- Parameters:
serialized (bytes): The serialized configuration data. **kwargs: Additional keyword arguments to pass to the constructor.
- Returns:
ConfigurationBuilder: An instance of ConfigurationBuilder initialized with the deserialized configuration data.
- classmethod from_commandline_options(options)[source]¶
Creates an instance of ConfigurationBuilder from command line options.
- Parameters:
options: The command line options to use for building the configuration.
- Returns:
ConfigurationBuilder: An instance of ConfigurationBuilder configured according to the provided command line options.
- Return type: