plesty.lib.utils.config

Reading the YAML configuration a Plesty module ships and a run supplies.

Every Plesty module carries a config.yaml beside its package __init__ — the constants and running defaults the scaffold creates — and every experiment additionally reads a run configuration from a file the operator points at. Both were being loaded by a hand-written load_config copied into each module, which is why this lives here instead.

The split the platform assumes:

  • Environment (EnvSettings) — device addresses and credentials; never in a tracked file.

  • Packaged module config (module_config()) — constants of the module itself: which sub-devices a rig has, how long an operation may physically take. Ships in the wheel, changes with the code.

  • Run config (load_yaml()) — measurement tuning the operator varies per run, frozen into the run’s plan.

from plesty.lib.utils.config import load_yaml, module_config

budgets = module_config("plesty.qd_fss", "constants", "hwp")
tuning = load_yaml("config/default.yaml", default={})

Attributes

DEFAULT_CONFIG_FILE

_REQUIRED

Functions

load_yaml(→ Any)

Parse a YAML file.

module_config_path(→ pathlib.Path)

Return the path of the configuration file packaged with module.

module_config(→ Any)

Return the configuration a module ships, or one section of it.

Module Contents

plesty.lib.utils.config.DEFAULT_CONFIG_FILE = 'config.yaml'
plesty.lib.utils.config._REQUIRED
plesty.lib.utils.config.load_yaml(path: str | pathlib.Path, default: Any = _REQUIRED) Any

Parse a YAML file.

Parameters:
  • path (str | pathlib.Path) – The file to read.

  • default (Any) – Returned when the file does not exist. Without it a missing file raises — a run configured from a path that is not there is a mistake worth naming, not an empty configuration to proceed with.

Returns:

The parsed document, or default when the file is absent.

Raises:
  • FileNotFoundError – If the file is missing and no default was given.

  • ValueError – If the file is not valid YAML.

Return type:

Any

plesty.lib.utils.config.module_config_path(module: str | types.ModuleType, filename: str = DEFAULT_CONFIG_FILE) pathlib.Path

Return the path of the configuration file packaged with module.

Parameters:
  • module (str | types.ModuleType) – The module, or its importable name ("plesty.qd_fss").

  • filename (str) – Configuration file name beside the module’s __init__.

Returns:

The path, whether or not the file exists.

Raises:
  • ModuleNotFoundError – If module names something that cannot be imported.

  • ValueError – If the module has no location on disk.

Return type:

pathlib.Path

plesty.lib.utils.config.module_config(module: str | types.ModuleType, *keys: str, filename: str = DEFAULT_CONFIG_FILE) Any

Return the configuration a module ships, or one section of it.

Parameters:
  • module (str | types.ModuleType) – The module, or its importable name ("plesty.qd_fss").

  • *keys (str) – Path into the document, e.g. "constants", "hwp". Without keys the whole document is returned.

  • filename (str) – Configuration file name beside the module’s __init__.

Returns:

The document, or the addressed section.

Raises:
  • FileNotFoundError – If the module ships no such configuration file — an absent packaged config is a broken install, not a default.

  • KeyError – If a key is missing, naming the full path so the error says which constant the module forgot to declare.

  • ValueError – If the file is not valid YAML.

Return type:

Any