From 6528234608b66216843fe0ed17e78ef2b3e967dd Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 1 Jun 2020 02:27:27 -0700 Subject: [PATCH] Fix tesseract_ocr.py errors --- src/ocrmypdf/__init__.py | 1 + src/ocrmypdf/builtin_plugins/tesseract_ocr.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ocrmypdf/__init__.py b/src/ocrmypdf/__init__.py index 08da4d6f..d64253b8 100644 --- a/src/ocrmypdf/__init__.py +++ b/src/ocrmypdf/__init__.py @@ -36,5 +36,6 @@ from ocrmypdf.exceptions import ( TesseractConfigError, UnsupportedImageFormatError, ) +from ocrmypdf.pluginspec import OcrEngine, OrientationConfidence hookimpl = _HookimplMarker('ocrmypdf') diff --git a/src/ocrmypdf/builtin_plugins/tesseract_ocr.py b/src/ocrmypdf/builtin_plugins/tesseract_ocr.py index 4991baff..d5f5eb7b 100644 --- a/src/ocrmypdf/builtin_plugins/tesseract_ocr.py +++ b/src/ocrmypdf/builtin_plugins/tesseract_ocr.py @@ -120,8 +120,11 @@ def check_options(options): @hookimpl def validate(pdfinfo, options): + if not options.tesseract_env: + return + # If we are running a Tesseract spoof, ensure it knows what the input file is - if os.environ.get('PYTEST_CURRENT_TEST') and options.tesseract_env: + if os.environ.get('PYTEST_CURRENT_TEST'): options.tesseract_env['_OCRMYPDF_TEST_INFILE'] = os.fspath(options.input_file) # Tesseract 4.x can be multithreaded, and we also run multiple workers. We want @@ -135,6 +138,8 @@ def validate(pdfinfo, options): if not options.tesseract_env.get('OMP_THREAD_LIMIT', '').isnumeric(): tess_threads = min(3, options.jobs // len(pdfinfo), len(pdfinfo)) options.tesseract_env['OMP_THREAD_LIMIT'] = str(tess_threads) + else: + tess_threads = int(options.tesseract_env['OMP_THREAD_LIMIT']) if tess_threads > 1: log.info("Using Tesseract OpenMP thread limit %d", tess_threads)