Archives: can this host read and write each comic archive format.
Every probe imports its library inside the function. Reading a CBZ must never load rarfile or py7zr, and the doctor shares that contract: a broken import becomes a row here, not a crash at import time.
check_cb7(_ctx)
py7zr and the optional codecs it reaches for.
Source code in comicbox/doctor/archives.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 | def check_cb7(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""py7zr and the optional codecs it reaches for."""
try:
import py7zr
except ImportError as exc:
yield _row(
"CB7",
Status.MISSING,
detail=f"can't import {exc.name or 'py7zr'}: {exc}",
fix=reinstall_hint("py7zr"),
)
return
present, missing = _split_codecs({"brotli": _BROTLI_MODULES, "zstd": _ZSTD_MODULES})
if missing:
yield _missing_codecs_row("CB7", missing, "archives")
yield _row(
"CB7",
Status.OK,
found=f"py7zr {py7zr.__version__}",
detail=" ".join([*present, "ppmd bcj"]) + " · BCJ2 unsupported",
)
|
check_cbr(_ctx)
Extract a real compressed member with whichever tool rarfile picks.
Passing rarfile’s version check proves little: rarfile 4.5’s bsdtar backend can’t extract anything, and 7-Zip builds without the RAR codec say “Unsupported Method”. Only the probe answers the question.
Source code in comicbox/doctor/archives.py
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
216
217
218
219
220
221
222 | def check_cbr(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""
Extract a real compressed member with whichever tool rarfile picks.
Passing rarfile's version check proves little: rarfile 4.5's bsdtar
backend can't extract anything, and 7-Zip builds without the RAR
codec say "Unsupported Method". Only the probe answers the question.
"""
from comicbox._rar import import_rarfile, rar_unsupported_reason
rarfile = import_rarfile()
found = f"rarfile {rarfile.__version__}"
effective = _rar_effective_tool(rarfile)
passing = _rar_tools_passing(rarfile)
reason = rar_unsupported_reason()
if not reason:
crypto = _RAR_CRYPTO.get(getattr(rarfile, "_have_crypto", 0), "none")
yield _row(
"CBR",
Status.OK,
found=found,
detail=f"via {effective} · probe read OK · crypto: {crypto}",
)
elif passing:
yield _row(
"CBR",
Status.MISCONFIGURED,
found=found,
detail=f"{', '.join(passing)} can't extract RAR: {reason}",
fix=unrar_hint(),
)
else:
yield _row(
"CBR",
Status.MISSING,
found=found,
detail=f"no RAR tool found: {reason}",
fix=unrar_hint(),
)
|
check_cbt(_ctx)
Every compressed tar flavor this Python’s tarfile can open.
Source code in comicbox/doctor/archives.py
248
249
250
251
252
253
254
255
256
257
258
259 | def check_cbt(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""Every compressed tar flavor this Python's tarfile can open."""
present, missing = _split_codecs(
{
codec: (_TAR_CODEC_MODULES.get(codec, codec),)
for codec in tarfile.TarFile.OPEN_METH
if codec != "tar"
}
)
if missing:
yield _missing_codecs_row("CBT", missing, "tarballs")
yield _row("CBT", Status.OK, detail=" ".join(present))
|
check_cbz(_ctx)
Zip needs zlib to write, and zipremove’s remove/repack to rewrite tags.
Source code in comicbox/doctor/archives.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 | def check_cbz(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""Zip needs zlib to write, and zipremove's remove/repack to rewrite tags."""
if not _importable("zlib"):
yield _row(
"CBZ",
Status.MISSING,
detail="no zlib: CBZs can't be written",
fix="use a Python built with zlib",
)
return
from zipremove import ZipFile
found = f"zipremove {dist_version('zipremove')}"
if lacking := [name for name in ("remove", "repack") if not hasattr(ZipFile, name)]:
yield _row(
"CBZ",
Status.WRONG_VERSION,
found=found,
detail=f"zipremove lacks {', '.join(lacking)}: tags can't be rewritten",
fix=f"pip install '{pinned('zipremove')}'",
)
return
codecs = dict(_ZIP_CODECS)
if hasattr(zipfile, "ZIP_ZSTANDARD"): # Python 3.14+
codecs["zstd"] = ("compression.zstd",)
present, missing = _split_codecs(codecs)
if missing:
yield _missing_codecs_row("CBZ", missing, "members")
yield _row("CBZ", Status.OK, found=found, detail=" ".join(["deflate", *present]))
|
check_pdf(_ctx)
Check the optional PDF extra: absent is fine, installed but broken is not.
Source code in comicbox/doctor/archives.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 | def check_pdf(_ctx: DoctorContext) -> Iterator[CheckResult]:
"""Check the optional PDF extra: absent is fine, installed but broken is not."""
installed = dist_version(PDF_DIST)
if not installed:
yield _row(
"PDF",
Status.OFF,
detail=f"{PDF_DIST} not installed",
fix="pip install 'comicbox[pdf]'",
)
return
found = f"{PDF_DIST} {installed}"
from packaging.requirements import Requirement
req = Requirement(pinned(PDF_DIST))
if req.specifier and not req.specifier.contains(installed, prereleases=True):
yield _row(
"PDF",
Status.WRONG_VERSION,
found=found,
detail=f"comicbox requires {req}",
fix=f"pip install '{req}'",
)
return
from comicbox._pdf import PDF_ENABLED
if not PDF_ENABLED:
# _pdf.py swallowed the error at import time. A failed import isn't
# cached in sys.modules, so importing again raises it again.
try:
import_module("pdffile")
except Exception as exc: # _pdf.py catches the same
yield _pdf_import_failure(exc)
return
import pymupdf
if all(dist_version(name) for name in _PYMUPDF_DISTS):
# pip leaves the old pymupdf behind when an upgrade swaps in
# pymupdf-lite, and the two install the same files.
yield _row(
"PDF",
Status.WARN,
detail="pymupdf and pymupdf-lite overwrite each other's files",
fix="pip uninstall -y pymupdf && pip install --force-reinstall pymupdf-lite",
)
# VersionBind, not a distribution's version: either one provides pymupdf.
yield _row(
"PDF",
Status.OK,
found=found,
detail=f"PyMuPDF {pymupdf.VersionBind} · MuPDF {pymupdf.VersionFitz}",
)
|
unrar_hint()
How to install RARLAB unrar here.
Source code in comicbox/doctor/archives.py
| def unrar_hint() -> str:
"""How to install RARLAB unrar here."""
return _UNRAR_HINTS.get(_detect_pkg_manager(), _UNRAR_HINT_DEFAULT)
|