Refactor fitz ImportError trap

This commit is contained in:
James R. Barlow
2018-03-27 21:38:02 -07:00
parent 112e8d6c18
commit 5becfcf8ea
5 changed files with 11 additions and 19 deletions

View File

@@ -32,11 +32,6 @@ import argparse
import PyPDF2 as pypdf
import PIL
try:
import fitz
except ImportError:
fitz = None
import ruffus.ruffus_exceptions as ruffus_exceptions
import ruffus.cmdline as cmdline
import ruffus.proxy_logger as proxy_logger
@@ -47,6 +42,7 @@ from .pdfa import file_claims_pdfa
from .helpers import is_iterable_notstr, re_symlink, is_file_writable, \
available_cpu_count
from .exec import tesseract, qpdf, ghostscript
from .lib import fitz
from . import PROGRAM_NAME, VERSION
from .exceptions import ExitCode, ExitCodeException, MissingDependencyError, \

View File

@@ -1,4 +1,3 @@
"""Bindings to external libraries"""
# © 2017 James R. Barlow: github.com/jbarlow83
#
# This file is part of OCRmyPDF.
@@ -15,3 +14,10 @@
#
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
"""Bindings to external libraries"""
try:
import fitz
except ImportError:
fitz = None

View File

@@ -29,11 +29,7 @@ from enum import Enum
from contextlib import contextmanager
import PyPDF2 as pypdf
try:
import fitz
except ImportError:
fitz = None
from .lib import fitz
from .helpers import universal_open, fspath

View File

@@ -34,15 +34,12 @@ from .pdfinfo import PdfInfo, Encoding, Colorspace
from .pdfa import generate_pdfa_ps
from .helpers import re_symlink, is_iterable_notstr, page_number
from .exec import ghostscript, tesseract, qpdf
from .lib import fitz
from .exceptions import PdfMergeFailedError, UnsupportedImageFormatError, \
DpiError, PriorOcrFoundError, InputFileError
from . import leptonica
from . import PROGRAM_NAME, VERSION
try:
import fitz
except ImportError:
fitz = None
VECTOR_PAGE_DPI = 400

View File

@@ -18,13 +18,10 @@
import pytest
import PyPDF2 as pypdf
try:
import fitz
except ImportError:
fitz = None
from ocrmypdf.pdfa import file_claims_pdfa
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.lib import fitz
# pytest.helpers is dynamic
# pylint: disable=no-member