Config: the files and env vars a run would read, and what they say.
A run logs most of these findings once, as a warning, and carries on: a broken user config is skipped, a typo’d key is silently dropped, a legacy env var is ignored. The doctor turns each into a row, by calling the code the warning comes from rather than by capturing log output.
check_env_vars(_ctx)
Env vars that look like settings but are no longer, or never were, read.
Source code in comicbox/doctor/settings.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299 | def check_env_vars(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""Env vars that look like settings but are no longer, or never were, read."""
for old, new in _LEGACY_ENV_VARS.items():
if old in os.environ:
yield _row(
"env var",
Status.WARN,
found=old,
detail="no longer read",
fix=f"rename it {new}",
)
if _IGNORED_CONFIG_ENV in os.environ:
yield _row(
"env var",
Status.WARN,
found=_IGNORED_CONFIG_ENV,
detail="doesn't load a config file",
fix="pass --config PATH instead",
)
|
check_files(ctx)
Each config file a run reads: the --config file, then the user config.
Source code in comicbox/doctor/settings.py
| def check_files(ctx: DoctorContext) -> Iterator[CheckResult]:
"""Each config file a run reads: the ``--config`` file, then the user config."""
if path := _cli_config_path(ctx):
yield _check_cli_config(path)
yield _check_user_config()
|
check_unknown_keys(ctx)
Keys a run silently drops, in each config file and the environment.
Source code in comicbox/doctor/settings.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278 | def check_unknown_keys(ctx: DoctorContext) -> Iterator[CheckResult]:
"""Keys a run silently drops, in each config file and the environment."""
known = _known_tree()
candidates = (_cli_config_path(ctx), _user_config_path())
# --config may name the user config itself; report its keys once.
paths = {path.resolve(): path for path in candidates if path}
for path in paths.values():
for key_path, siblings in _unknown_paths(_load_yaml(path), known):
yield _unknown_key_row(path, key_path, siblings)
for name in sorted(os.environ):
if not name.startswith(_ENV_PREFIX) or name in _LEGACY_ENV_VARS:
continue
for key_path, siblings in _unknown_paths(_env_tree(name), known):
yield _unknown_key_row(f"env {name}", key_path, siblings)
|
check_values(ctx)
Validate the layered config exactly as a run would.
A run turns these errors into a one-line exit; the doctor reports them and keeps going. On success the later checks get the settings.
Source code in comicbox/doctor/settings.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | def check_values(ctx: DoctorContext) -> Iterator[CheckResult]:
"""
Validate the layered config exactly as a run would.
A run turns these errors into a one-line exit; the doctor reports them
and keeps going. On success the later checks get the settings.
"""
from comicbox.config import get_config
try:
ctx.settings = get_config(ctx.args)
except ConfigReadError:
# Only the --config file raises this here (a broken user config
# is skipped), and its own row already says why.
return
except (ConfigError, ValueError, TypeError) as exc:
yield _row(
"values",
Status.MISCONFIGURED,
detail=str(exc),
fix="fix the setting named above",
)
return
yield _row("values", Status.OK, detail="validated")
|