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.

Parameters:
  • key (str) – The key to be returned.

  • default (object) – The default value to be returned if the key is not found.

Returns:

The value of the key, or the default if the key is not found.

Return type:

object

items()

Return the items.

Returns:

The items.

Return type:

list

keys()

Return the keys.

Returns:

The keys.

Return type:

list

update(*args, **kwargs)

Update the object with the values from another object.

Parameters:
  • args (object) – The object to be updated with.

  • kwargs (object) – The object to be updated with.

Returns:

None

values()

Return the values.

Returns:

The values.

Return type:

list

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:
  • data (dict or None) – Dictionary containing the configuration for the interface

  • directory (str) – Directory where the configuration file was loaded from (used for resolving relative paths)

  • user_file (str) – Filename of the configuration file

Returns:

None

Raises:

ValueError – If required arguments are missing or if inheritance configuration is invalid

property user_file

Return the user file.

Returns:

The user file.

Return type:

str

property directory

Return the directory.

Returns:

The directory.

Return type:

str

get_output_columns()[source]

Return the output columns.

Returns:

The output columns.

Return type:

list

get_cache_columns()[source]

Return the cache columns.

Returns:

The cache columns.

Return type:

list

get(key, default=None)

Return the value of the key providing a default if the key is not found.

Parameters:
  • key (str) – The key to be returned.

  • default (object) – The default value to be returned if the key is not found.

Returns:

The value of the key.

Return type:

object

items()

Return the items.

Returns:

The items.

Return type:

list

keys()

Return the keys.

Returns:

The keys.

Return type:

list

update(*args, **kwargs)

Update the object with the values from another object.

Parameters:
  • args (object) – The object to be updated with.

  • kwargs (object) – The object to be updated with.

Returns:

None

values()

Return the values.

Returns:

The values.

Return type:

list

classmethod default_config_file()[source]

Default name of the interface configuration file.

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:

Interface

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.

classmethod from_yaml(text)[source]

Read an interface from yaml text.

Parameters:

text (str) – yaml text of interface.

Returns:

A lynguine.config.interface.Interface object.

Return type:

Interface

to_yaml()[source]

Write the interface to yaml text.

Returns:

yaml text of interface.

Return type:

str