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 <no@anonymousplanet.org>
This commit is contained in:
nopeitsnothing
2026-05-23 22:53:28 -04:00
parent 85ea1fee66
commit 343ad7f037
+21
View File
@@ -119,6 +119,25 @@ def _check_qpdf() -> bool:
).returncode == 0 ).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( def convert_pdf_to_dark(
input_path: str | Path, input_path: str | Path,
output_path: str | Path, output_path: str | Path,
@@ -138,6 +157,8 @@ def convert_pdf_to_dark(
input_path = str(input_path) input_path = str(input_path)
output_path = str(output_path) output_path = str(output_path)
_check_dependencies()
with tempfile.TemporaryDirectory() as tmp: with tempfile.TemporaryDirectory() as tmp:
# 1. Rasterize all pages # 1. Rasterize all pages
prefix = os.path.join(tmp, 'page') prefix = os.path.join(tmp, 'page')