diff --git a/src/ocrmypdf/_validation.py b/src/ocrmypdf/_validation.py index 3a611274..6dc0566b 100644 --- a/src/ocrmypdf/_validation.py +++ b/src/ocrmypdf/_validation.py @@ -52,17 +52,6 @@ def check_options_languages( system_lang = locale.getlocale()[0] if system_lang and not system_lang.startswith('en'): log.debug("No language specified; assuming --language %s", DEFAULT_LANGUAGE) - DENIED_LANGUAGES = {'equ', 'osd'} - if DENIED_LANGUAGES & set(options.languages): - log.warning( - "The following languages for Tesseract's internal use and should not " - "be issued explicitly: " - f"{', '.join(DENIED_LANGUAGES)}\n" - "OCRmyPDF will ignore them." - ) - options.languages = [ - lang for lang in options.languages if lang not in DENIED_LANGUAGES - ] if not ocr_engine_languages: return diff --git a/src/ocrmypdf/builtin_plugins/tesseract_ocr.py b/src/ocrmypdf/builtin_plugins/tesseract_ocr.py index 3d6fc212..ae0f0763 100644 --- a/src/ocrmypdf/builtin_plugins/tesseract_ocr.py +++ b/src/ocrmypdf/builtin_plugins/tesseract_ocr.py @@ -14,6 +14,7 @@ from ocrmypdf import hookimpl from ocrmypdf._exec import tesseract from ocrmypdf._jobcontext import PageContext from ocrmypdf.cli import numeric, str_to_int +from ocrmypdf.exceptions import BadArgsError from ocrmypdf.helpers import clamp from ocrmypdf.imageops import calculate_downsample, downsample_image from ocrmypdf.pluginspec import OcrEngine @@ -164,6 +165,14 @@ def check_options(options): "The --tesseract-pagesegmode argument you select will disable OCR. " "This may cause processing to fail." ) + DENIED_LANGUAGES = {'equ', 'osd'} + if DENIED_LANGUAGES & set(options.languages): + raise BadArgsError( + "The following languages for Tesseract's internal use and should not " + "be issued explicitly: " + f"{', '.join(DENIED_LANGUAGES & set(options.languages))}\n" + "Remove them from the -l/--language argument." + ) @hookimpl diff --git a/tests/test_tesseract.py b/tests/test_tesseract.py index 74552db9..0132795f 100644 --- a/tests/test_tesseract.py +++ b/tests/test_tesseract.py @@ -13,9 +13,9 @@ import pytest from ocrmypdf import pdfinfo from ocrmypdf._exec import tesseract -from ocrmypdf.exceptions import MissingDependencyError +from ocrmypdf.exceptions import BadArgsError, ExitCode, MissingDependencyError -from .conftest import check_ocrmypdf +from .conftest import check_ocrmypdf, run_ocrmypdf_api # pylint: disable=redefined-outer-name @@ -144,3 +144,10 @@ def test_tesseract_log_output_raises(caplog): with pytest.raises(tesseract.TesseractConfigError): tesseract.tesseract_log_output(b'parameter not found: moo') assert 'not found' in caplog.text + + +def test_blocked_language(resources, no_outpdf): + infile = resources / 'masks.pdf' + for bad_lang in ['osd', 'equ']: + with pytest.raises(BadArgsError): + run_ocrmypdf_api(infile, no_outpdf, '-l', bad_lang)