bloc.chem.config_access#

Shared dict-or-attribute config access helper.

STONE configs show up in two shapes across the codebase: plain nested dicts (cfg["settings"]["get_carbon_yield"]["n_C_min"]) and attrs-style objects with the same structure as attributes (config.settings.get_carbon_yield.n_C_min). get_attr_or_key() probes both without the caller needing to know which shape it was handed.

Functions#

get_attr_or_key(obj, key)

Return obj[key] (mapping) or obj.key (attribute), else None.

get_path(obj, *path)

Walk a chain of get_attr_or_key() lookups, short-circuiting on None.

Module Contents#

bloc.chem.config_access.get_attr_or_key(obj, key)#

Return obj[key] (mapping) or obj.key (attribute), else None.

Mirrors the dual-access pattern originally local to bloc.reporting.orchestrator._config_mechanism_names().

bloc.chem.config_access.get_path(obj, *path)#

Walk a chain of get_attr_or_key() lookups, short-circuiting on None.

get_path(config, "settings", "get_carbon_yield", "n_C_min") works whether config (and each nested level) is a dict or an attrs-style object.