mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 05:39:57 -05:00
API startup no longer imports pymupdf (#946)
pymupdf 2.0 imports pymupdf.layout and onnxruntime, which every API start paid for (about 2.5 s on a Pi 4) although only PDF extraction uses it. It is now imported when a PDF is extracted. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cafa2a2279
commit
ba9b47edf3
2 changed files with 17 additions and 6 deletions
|
|
@ -25,11 +25,6 @@ except ImportError:
|
|||
ebooklib = None
|
||||
epub = None
|
||||
|
||||
try:
|
||||
import pymupdf
|
||||
except ImportError:
|
||||
pymupdf = None
|
||||
|
||||
try:
|
||||
import docx
|
||||
except ImportError:
|
||||
|
|
@ -252,7 +247,11 @@ def _parse_pdf_date(date_str: str):
|
|||
|
||||
def extract_pdf(path: pathlib.Path) -> DocMetadata:
|
||||
"""Extract metadata from a PDF using pymupdf."""
|
||||
if pymupdf is None:
|
||||
# Not imported at module level: pymupdf also imports pymupdf.layout and onnxruntime (~2s on a Pi 4), which must
|
||||
# stay out of API startup.
|
||||
try:
|
||||
import pymupdf
|
||||
except ImportError:
|
||||
logger.error(f'Cannot extract PDF metadata: pymupdf is not installed')
|
||||
return DocMetadata(title=Indexer.get_title(path))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue