Source code for thesis.workflows.mrtrix3.config.values

"""MRtrix3 configuration value resolution.

The ``mrtrix3:`` block is an optional dict field on :class:`PipelineConfig`
(default: empty dict).  This helper unifies attribute-style and dict-style
access so callers can read overrides without caring how the loader chose
to materialise the block.
"""

from typing import Optional

from thesis.core.config import PipelineConfig


[docs] def resolve_mrtrix3_value( config: PipelineConfig, key: str, default: Optional[str] = None, ) -> str: """Read a value from ``config.mrtrix3`` (dict or attribute) with a default. ``config.mrtrix3`` is declared as a ``Dict[str, Any]`` on :class:`PipelineConfig`, but this helper also accepts an attribute-style object for forward-compatibility with a future typed model. Args: config: Pipeline configuration. key: Configuration key to retrieve. default: Value returned when the key is missing. Returns: The configured value as a string, or ``default``. """ mrtrix3_cfg = getattr(config, "mrtrix3", None) if isinstance(mrtrix3_cfg, dict): value = mrtrix3_cfg.get(key) if value is not None: return str(value) elif mrtrix3_cfg is not None: value = getattr(mrtrix3_cfg, key, None) if value is not None: return str(value) return str(default) if default is not None else ""