Skip to content

comicbox.doctor ¶

comicbox doctor: report on everything outside comicbox that it depends on.

Each check reports rows: OK, WARN, OFF (optional, not set up), MISSING, WRONG VERSION, MISCONFIGURED or ERROR, with a one-line fix for anything that isn’t OK. Any failure makes the exit code 1, so comicbox doctor -q doubles as a Docker or CI health check.

run_checks is the library API: it returns the rows as data and prints nothing. main is comicbox doctor.

Offline and read-only by default, apart from confuse creating the config directory, which every run does too. --online all (or a list of sources) adds exactly one request per configured source named, which counts against that source’s rate limit, and Comic Vine’s creates the online cache directory for its rate-limit bucket.

CheckResult dataclass ¶

One row of the report.

found is what was found: a version, a tool, or a path. A Path renders as a path. fix is a one-line hint for anything not OK. None of these ever carry a secret value.

Source code in comicbox/doctor/result.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@dataclass(frozen=True, slots=True)
class CheckResult:
    """
    One row of the report.

    ``found`` is what was found: a version, a tool, or a path. A ``Path``
    renders as a path. ``fix`` is a one-line hint for anything not OK.
    None of these ever carry a secret value.
    """

    section: str
    name: str
    status: Status
    found: str | Path = ""
    detail: str = ""
    fix: str = ""

DoctorReport dataclass ¶

Every row the checks produced, plus the host they ran on.

Source code in comicbox/doctor/result.py
53
54
55
56
57
58
59
60
61
62
63
64
@dataclass(frozen=True, slots=True)
class DoctorReport:
    """Every row the checks produced, plus the host they ran on."""

    #: comicbox version, Python, platform: information only.
    header: tuple[str, ...]
    results: tuple[CheckResult, ...]

    @property
    def exit_code(self) -> int:
        """1 if anything comicbox needs is broken, else 0."""
        return int(any(result.status.is_failure for result in self.results))

exit_code property ¶

1 if anything comicbox needs is broken, else 0.

Status ¶

Bases: StrEnum

How one dependency or setting checked out.

Source code in comicbox/doctor/result.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Status(StrEnum):
    """How one dependency or setting checked out."""

    OK = "OK"
    #: Works, but something about it deserves a look.
    WARN = "WARN"
    #: Optional and not set up.
    OFF = "OFF"
    MISSING = "MISSING"
    WRONG_VERSION = "WRONG VERSION"
    MISCONFIGURED = "MISCONFIGURED"
    #: The check itself couldn't finish: the probe crashed.
    ERROR = "ERROR"

    @property
    def is_failure(self) -> bool:
        """Whether this status means something comicbox needs is broken."""
        return self in _FAILURES

is_failure property ¶

Whether this status means something comicbox needs is broken.

main(params) ¶

Run comicbox doctor on the args after doctor; return the exit code.

Source code in comicbox/doctor/__init__.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def main(params: Sequence[str]) -> int:
    """Run ``comicbox doctor`` on the args after ``doctor``; return the exit code."""
    from comicbox.doctor.render import render_report

    cns = _build_parser().parse_args(params)
    # Not a setting: keep it out of the config tree.
    problems_only = vars(cns).pop("problems")
    if cns.paths:
        sys.stderr.write(
            f"comicbox doctor: ignoring {len(cns.paths)} path(s); "
            "the doctor reads no comics.\n"
        )
        cns.paths = []
    _hold_logging(cns)
    online_sources = tuple(cns.online_sources or ())
    if online_sources:
        from comicbox.version import set_user_agent_context

        # So Metron's operators can tell probe traffic from tagging.
        set_user_agent_context("cli", client="doctor")
    ctx = DoctorContext(Namespace(comicbox=cns), online_sources=online_sources)
    report = _run(ctx)
    theme = ctx.settings.general.theme if ctx.settings else None
    render_report(report, theme=theme, problems_only=problems_only)
    return report.exit_code

run_checks(args=None, *, online_sources=()) ¶

Check comicbox’s external dependencies and config.

args is what a run would get, Namespace(comicbox=...), so the report describes the config that run would see. None checks the environment and config files alone. online_sources names the sources to verify with one live request each, "all" for every configured one.

Source code in comicbox/doctor/__init__.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def run_checks(
    args: Namespace | None = None, *, online_sources: Iterable[str] = ()
) -> DoctorReport:
    """
    Check comicbox's external dependencies and config.

    ``args`` is what a run would get, ``Namespace(comicbox=...)``, so the
    report describes the config that run would see. None checks the
    environment and config files alone. ``online_sources`` names the
    sources to verify with one live request each, ``"all"`` for every
    configured one.
    """
    ctx = DoctorContext(args) if args is not None else DoctorContext()
    ctx.online_sources = tuple(online_sources)
    return _run(ctx)