lynguine.config
The config module provides functionality for configuration management, including context and interface definitions.
Context Module
- class lynguine.config.context.Context(name=None, data=None)[source]
Bases:
_Config
Load in some default configuration from the context.
Load in the configuration from the context.
- Parameters:
name (str) – The name of the context.
- Raises:
ValueError – If no configuration file is found.
- get(key, default=None)
Return the value of the key, or the default if the key is not found.
- update(*args, **kwargs)
Update the object with the values from another object.
Interface Module
- class lynguine.config.interface.Interface(data=None, directory=None, user_file=None)[source]
Bases:
_HConfig
A hierarchical interface configuration for data-oriented architecture.
The Interface class manages configuration for data flows within the lynguine data-oriented architecture. It provides a mechanism for defining inputs, outputs, computations, parameters, and other components of a data processing pipeline.
Key features: - Hierarchical inheritance: An interface can inherit from a parent interface,
allowing for composition and reuse of configurations.
Input/output management: Defines how data is read from and written to various sources.
Computation specification: Defines computations to be performed on the data.
Parameter handling: Manages configuration parameters that control processing.
The interface can be loaded from YAML files, with support for environment variable expansion and directory-relative paths. When inheriting from another interface, the child can specify which elements to ignore or append from the parent.
Inheritance is particularly useful when outputs from a parent interface are used as inputs to the child interface, creating a processing pipeline.
Initialize a new Interface instance with the provided configuration data.
This constructor sets up the interface configuration, processes inheritance if specified, and expands environment variables in the configuration values.
The initialization process: 1. Validates required arguments (directory and user_file) 2. Stores configuration data, directory, and filename 3. Sets up parent interface if inheritance is specified 4. Processes parent interface (resolving inheritance relationships) 5. Expands environment variables in configuration values
When inheritance is specified, the parent interface is loaded using the directory and filename provided in the “inherit” section of the configuration. The parent’s attributes can be selectively ignored or appended to the child interface using the “ignore” and “append” lists in the “inherit” section.
- Parameters:
- Returns:
None
- Raises:
ValueError – If required arguments are missing or if inheritance configuration is invalid
- get(key, default=None)
Return the value of the key providing a default if the key is not found.
- update(*args, **kwargs)
Update the object with the values from another object.
- classmethod from_file(user_file=None, directory='.', field=None, raise_error_if_not_found=True)[source]
Construct an Interface instance by loading configuration from a YAML file.
This factory method creates an Interface object by reading a YAML configuration file. It handles file path resolution, YAML parsing, and hierarchical interface loading if inheritance is specified in the configuration.
The configuration file should be in YAML format and can include interface specifications for inputs, outputs, computations, and other configuration.
- Parameters:
user_file (str or list[str] or None) – The name of the configuration file to load, or a list of filenames to try in order (first existing file will be used). If None, the default config filename will be used.
directory (str) – The directory to look for the configuration file in, defaults to current directory.
field (str or None) – Optional specific field to extract from the loaded YAML (for when the interface is nested within a larger configuration file).
raise_error_if_not_found (bool) – Whether to raise an error if the file is not found or empty, defaults to True. If False, an empty interface will be created.
- Returns:
A new Interface instance loaded from the specified file.
- Return type:
- Raises:
ValueError – If the file is not found or empty (and raise_error_if_not_found is True), or if the YAML cannot be parsed, or if a specified field is not found.