mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Solve import errors by lazy-loading fitz module
Qubes does on-host pixels-to-pdf whereas the containers version doesn't. This leads to an issue where on the containers version it tries to load fitz, which isn't installed there, just because it's trying to check if it should run the Qubes version. The error it was showing was something like this: ImportError while loading conftest '/home/user/dangerzone/tests/conftest.py'. tests/__init__.py:8: in <module> from dangerzone.document import SAFE_EXTENSION dangerzone/__init__.py:16: in <module> from .gui import gui_main as main dangerzone/gui/__init__.py:28: in <module> from ..isolation_provider.qubes import Qubes, is_qubes_native_conversion dangerzone/isolation_provider/qubes.py:15: in <module> from ..conversion.pixels_to_pdf import PixelsToPDF dangerzone/conversion/pixels_to_pdf.py:16: in <module> import fitz E ModuleNotFoundError: No module named 'fitz' For context see discussion in [1]. [1]: https://github.com/freedomofpress/dangerzone/pull/622#issuecomment-1839164885
This commit is contained in:
parent
773fcfa75b
commit
6f61e44502
1 changed files with 3 additions and 2 deletions
|
@ -13,8 +13,6 @@ import shutil
|
|||
import sys
|
||||
from typing import Optional
|
||||
|
||||
import fitz
|
||||
|
||||
from .common import DEFAULT_DPI, DangerzoneConverter, get_tessdata_dir, running_on_qubes
|
||||
|
||||
|
||||
|
@ -26,6 +24,9 @@ class PixelsToPDF(DangerzoneConverter):
|
|||
if tempdir is None:
|
||||
tempdir = "/tmp"
|
||||
|
||||
# XXX lazy loading of fitz module to avoid import issues on non-Qubes systems
|
||||
import fitz
|
||||
|
||||
num_pages = len(glob.glob(f"{tempdir}/dangerzone/page-*.rgb"))
|
||||
total_size = 0.0
|
||||
|
||||
|
|
Loading…
Reference in a new issue