Skip to content

comicbox.doctor.packages ¶

Python packages: comicbox’s own requirements against what’s installed.

The pins come from the installed distribution’s metadata, never from a hardcoded list, so the doctor can’t drift from pyproject.toml. uv’s editable dev install ships that metadata too.

check_requirements(_ctx) ¶

Check every base requirement’s installed version against its pin.

Extras are left to their feature row (the PDF row checks comicbox-pdffile), so one problem never counts twice. A broken transitive dependency surfaces in the feature rows as an import error naming the module, which says more than a version would.

Source code in comicbox/doctor/packages.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def check_requirements(_ctx: DoctorContext) -> Iterator[CheckResult]:
    """
    Check every base requirement's installed version against its pin.

    Extras are left to their feature row (the PDF row checks
    comicbox-pdffile), so one problem never counts twice. A broken
    transitive dependency surfaces in the feature rows as an import error
    naming the module, which says more than a version would.
    """
    try:
        requirements = _requirements()
    except PackageNotFoundError:
        yield CheckResult(
            SECTION,
            PACKAGE_NAME,
            Status.WARN,
            detail="comicbox metadata unavailable: pins not checked",
            fix=f"reinstall comicbox: pip install --force-reinstall {PACKAGE_NAME}",
        )
        return
    env = {"extra": ""}
    satisfied = 0
    for req in requirements:
        if req.marker is not None and not req.marker.evaluate(env):
            continue
        if failure := _check_requirement(req):
            yield failure
        else:
            satisfied += 1
    if satisfied:
        yield CheckResult(
            SECTION,
            "requirements",
            Status.OK,
            detail=f"{satisfied} satisfied",
        )

dist_version(name) ¶

Return an installed distribution’s version, or “” if it’s absent.

Source code in comicbox/doctor/packages.py
36
37
38
39
40
41
def dist_version(name: str) -> str:
    """Return an installed distribution's version, or "" if it's absent."""
    try:
        return version(name)
    except PackageNotFoundError:
        return ""

host_header() ¶

Describe the host: comicbox, Python and the platform it runs on.

Source code in comicbox/doctor/packages.py
158
159
160
161
162
163
164
165
166
def host_header() -> tuple[str, ...]:
    """Describe the host: comicbox, Python and the platform it runs on."""
    comicbox = f"comicbox {dist_version(PACKAGE_NAME) or 'unknown version'}"
    if kind := _install_kind():
        comicbox += f" ({kind})"
    parts = [comicbox, _python(), platform.platform(terse=True)]
    if sys.platform == "linux" and Path("/.dockerenv").exists():
        parts.append("Docker")
    return tuple(parts)

pinned(name) ¶

Return name with comicbox’s pin, e.g. py7zr~=1.1.0, for fix hints.

Source code in comicbox/doctor/packages.py
50
51
52
53
54
55
56
57
58
59
60
def pinned(name: str) -> str:
    """Return ``name`` with comicbox's pin, e.g. ``py7zr~=1.1.0``, for fix hints."""
    target = canonicalize_name(name)
    try:
        requirements = _requirements()
    except PackageNotFoundError:
        return name
    for req in requirements:
        if canonicalize_name(req.name) == target:
            return f"{req.name}{req.specifier}"
    return name

reinstall_hint(name) ¶

Return the pip command that reinstalls name at comicbox’s pin.

Source code in comicbox/doctor/packages.py
63
64
65
def reinstall_hint(name: str) -> str:
    """Return the pip command that reinstalls ``name`` at comicbox's pin."""
    return f"pip install --force-reinstall '{pinned(name)}'"