Skip to content

comicbox.doctor.result

What a doctor check reports: one row per thing checked.

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.

short_path(path)

Abbreviate the home directory to ~ for display.

Source code in comicbox/doctor/result.py
67
68
69
70
71
72
73
def short_path(path: str | Path) -> str:
    """Abbreviate the home directory to ``~`` for display."""
    path = Path(path)
    try:
        return str(Path("~") / path.relative_to(Path.home()))
    except (ValueError, RuntimeError):  # not under home, or no home at all
        return str(path)