Fix dependency-handling bugs: RAR probe, PDF guard, config errors - #229
Merged
Merged
Conversation
Found while planning `comicbox --doctor`.
- RAR support is probed by extracting a compressed member of a bundled
110-byte RAR5 archive (comicbox/_rar_probe.rar) through whichever tool
rarfile picks, instead of `which("unrar")`. rarfile 4.5's bsdtar
command line opens a file named `--`, and Homebrew's 7zz has no RAR
codec: both pass rarfile's tool check and extract nothing, so trusting
that check would make every Mac look CBR-capable to Codex.
- RarCannotExec, and tool failures while constructing a RarFile (RAR3
comments), map to UnsupportedArchiveTypeError as BadRarFile already did.
- is_pdf_supported() returns PDF_ENABLED instead of checking sys.modules,
which is also true when the guard rejected pdffile or Codex imported it.
- _pdf.py survives any pdffile import failure (pymupdf asserts its
libmupdf version at import) and warns unless pdffile is simply absent.
- A malformed user config no longer drops the package defaults beneath
it. Config errors raise ConfigurationError(ComicboxError, ValueError);
the CLI prints those and confuse's ConfigError as one line, escaped so
rich keeps "[digital]" instead of eating it as markup.
- online.tuning.per_source blocks are type-checked with the existing but
unused tuning template; unknown source names warn and are skipped.
- _archive_errors() tolerates an unimportable rarfile or py7zr instead of
raising inside the except clause and aborting batch reads.
- Correct the zipremove comment: 3.14 has no ZipFile.remove/repack.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seven bugs in how comicbox detects and reports its external dependencies, found while planning a
comicbox --doctorcommand.Changes
is_unrar_supported()/check_unrar_executable()now extract the compressed member of a bundled 110-byte RAR5 archive (comicbox/_rar_probe.rar) through whichever tool rarfile selects, via the new cachedcomicbox._rar.rar_unsupported_reason(). Checkingwhich("unrar")was wrong in both directions, and so is trustingrarfile.tool_setup(). rarfile 4.5's bsdtar command line opens a file named--, and Homebrew's7zzhas no RAR codec. Both pass rarfile's tool check but extract nothing, so on every Mac the check would report CBR support that doesn't work.UnsupportedArchiveTypeError.RarCannotExec, and tool failures while constructing aRarFile(RAR3 compressed comments), now map the wayBadRarFilealready did, when the probe says the host can't extract.is_pdf_supported()returnsPDF_ENABLED. It used to check"pdffile" in sys.modules, which is also true when the guard rejected pdffile or the embedding app imported it._pdf.pysurvives any pdffile import failure; pymupdf asserts its libmupdf version at import, which raised past theexcept ImportError. It warns unless pdffile is simply not installed.config.yamlno longer drops the package defaults. Previously validation then died oncomicbox.paths not found.ConfigurationError(ComicboxError, ValueError), so callers catchingValueErrorare unaffected. The CLI prints those and confuse'sConfigErroras one yellow line instead of a traceback. Messages are escaped so rich no longer eats[digital]as markup.online.tuning.per_sourceblocks are type-checked. They use the existing but previously unused tuning template. Null blocks are allowed, and unknown source names warn and are skipped._archive_errors()tolerates an unimportable rarfile or py7zr. It previously raised inside theexceptclause and aborted batch reads.ZipFile.remove/repack.Codex impact (after it bumps comicbox)
Comicbox.is_unrar_supported()(codex/librarian/fs/filters.py), which now runs one cached probe subprocess per process.Testing
make fix,make lint(ruff, basedpyright 0 warnings, vulture, complexipy) andmake tyare clean.radon cc --min Candradon mi --min Bon the changed files print nothing.make test: 2289 passed, 1 pre-existing skip.tests/unit/test_rar_tool_probe.py,test_pdf_import_guard.py,test_config_errors.py,test_process_archive_errors.py, plus three CLI cases intests/cli/test_cli_exit_code.py.develop, run in a throwaway worktree. The RAR-probe and config tests import new names, so that check couldn't apply to them.comicbox/_rar_probe.rar.🤖 Generated with Claude Code