From 343ad7f03736a8e990785fdc6f84dbffb971fbb6 Mon Sep 17 00:00:00 2001 From: nopeitsnothing Date: Sat, 23 May 2026 22:53:28 -0400 Subject: [PATCH] fix(convert): fail fast with helpful message if pdftoppm or qpdf missing Previously the script crashed with a FileNotFoundError traceback when system tools were absent. Now _check_dependencies() runs before any work begins and prints install instructions for Linux/WSL, macOS, and a pointer to develop.md for Windows. Signed-off-by: nopeitsnothing --- scripts/convert.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/convert.py b/scripts/convert.py index 11e81a9..ebc4440 100644 --- a/scripts/convert.py +++ b/scripts/convert.py @@ -119,6 +119,25 @@ def _check_qpdf() -> bool: ).returncode == 0 +def _check_dependencies() -> None: + """Verify required system tools are available before doing any work.""" + missing = [] + for tool in ('pdftoppm', 'qpdf'): + if subprocess.run(['which', tool], capture_output=True).returncode != 0: + missing.append(tool) + if missing: + tools = ', '.join(missing) + instructions = ( + f"Install with:\n" + f" Linux/WSL: sudo apt install poppler-utils qpdf\n" + f" macOS: brew install poppler qpdf\n" + f" Windows: see docs/code/develop.md" + ) + raise RuntimeError( + f"Missing required system tool(s): {tools}\n{instructions}" + ) + + def convert_pdf_to_dark( input_path: str | Path, output_path: str | Path, @@ -138,6 +157,8 @@ def convert_pdf_to_dark( input_path = str(input_path) output_path = str(output_path) + _check_dependencies() + with tempfile.TemporaryDirectory() as tmp: # 1. Rasterize all pages prefix = os.path.join(tmp, 'page')