Read config sources in order; template is the package’s settings.
Source code in comicbox/config/read.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 | def read_config_sources(
config: Configuration,
args: Namespace | Mapping | None,
template: Template | None = None,
) -> None:
"""Read config sources in order; ``template`` is the package's settings."""
# User config, then the package defaults beneath it. Read separately:
# confuse's read() adds them in that order, so a malformed user file
# raised before the defaults were ever added and validation then died
# on "comicbox.paths not found" instead of the user file being skipped.
try:
config.read(user=True, defaults=False)
except Exception as exc:
logger.warning(f"Ignoring user config: {exc}")
config.read(user=False, defaults=True)
# Args Specified Config File
if args:
_add_config_file(args, config)
# Env vars
_add_env(config, template)
# Args (highest priority — must override config files and env vars).
# Mapping uses .set() so it lands on top of the source stack like
# set_args() does for Namespace; .add() would put it BELOW the
# config_default.yaml loaded by .read() above.
if args:
if isinstance(args, Mapping):
config.set(args)
elif isinstance(args, Namespace): # pyright: ignore[reportUnnecessaryIsInstance]
# dots=True splits the CLI's dotted dests into the config tree.
config.set_args(args, dots=True)
|