From 751b50b573a797b349198bfa9b4e5eb6d1145d04 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:25:30 -0700 Subject: [PATCH] Chore: Read the OCRmyPDF sRGB profile on first use instead of at import --- src/paperless/parsers/tesseract.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/paperless/parsers/tesseract.py b/src/paperless/parsers/tesseract.py index 5a3b77f88..e8ff0f3b5 100644 --- a/src/paperless/parsers/tesseract.py +++ b/src/paperless/parsers/tesseract.py @@ -1,5 +1,6 @@ from __future__ import annotations +import functools import importlib.resources import logging import os @@ -39,9 +40,12 @@ if TYPE_CHECKING: logger = logging.getLogger("paperless.parsing.tesseract") -_SRGB_ICC_DATA: Final[bytes] = ( - importlib.resources.files("ocrmypdf.data").joinpath("sRGB.icc").read_bytes() -) + +@functools.cache +def _srgb_icc_data() -> bytes: + # Read on first use, importing ocrmypdf.data pulls in the whole ocrmypdf package + return importlib.resources.files("ocrmypdf.data").joinpath("sRGB.icc").read_bytes() + _SUPPORTED_MIME_TYPES: Final[dict[str, str]] = { "application/pdf": ".pdf", @@ -403,7 +407,7 @@ class RasterisedDocumentParser: pdfa_path = Path(self.tempdir) / "archive.pdf" try: with pikepdf.open(plain_pdf_path) as pdf: - cs = pdf.make_stream(_SRGB_ICC_DATA) + cs = pdf.make_stream(_srgb_icc_data()) cs["/N"] = 3 output_intent = pikepdf.Dictionary( Type=pikepdf.Name("/OutputIntent"),