apsbits.utils.config_loaders#

Configuration management for the instrument.

This module serves as the single source of truth for instrument configuration. It loads and validates the configuration from the iconfig.yml file and provides access to the configuration throughout the application.

Functions

get_config()

Get the current configuration.

load_config([config_path])

Load configuration from a YAML or TOML file.

load_config_yaml(config_obj)

Load configuration from a YAML file.

update_config(updates)

Update the current configuration.

validate_instrument_path([instrument_path, ...])

Validate if the provided instrument path is correct by checking for expected files and directories.

apsbits.utils.config_loaders.get_config() Dict[str, Any][source]#

Get the current configuration.

Returns:

The current configuration dictionary.

apsbits.utils.config_loaders.load_config(config_path: Path | None = None) Dict[str, Any][source]#

Load configuration from a YAML or TOML file.

Parameters:

config_path – Path to the configuration file.

Returns:

The loaded configuration dictionary.

Raises:
  • ValueError – If config_path is None or if the file extension is not supported.

  • FileNotFoundError – If the configuration file does not exist.

apsbits.utils.config_loaders.load_config_yaml(config_obj) dict[source]#

Load configuration from a YAML file.

Parameters:

config_path – Path to the configuration file.

Returns:

The loaded configuration dictionary.

Raises:

FileNotFoundError – If the configuration file does not exist.

apsbits.utils.config_loaders.update_config(updates: Dict[str, Any]) None[source]#

Update the current configuration.

Parameters:

updates – Dictionary of configuration updates.

apsbits.utils.config_loaders.validate_instrument_path(instrument_path: Path | None = None, expected_files: List[str] | None = None, expected_dirs: List[str] | None = None) Tuple[bool, str][source]#

Validate if the provided instrument path is correct by checking for expected files and directories.

Parameters:
  • instrument_path – Path to the instrument directory. If None, uses the path from the current config.

  • expected_files – List of files that should exist in the instrument directory.

  • expected_dirs – List of directories that should exist in the instrument directory.

Returns:

A tuple containing (is_valid, message) where is_valid is a boolean indicating if the path is valid, and message is a description of the validation result.