Rename ocrmypdf.exec -> ocrmypdf._exec
This commit is contained in:
@@ -28,6 +28,7 @@ from pikepdf.models.metadata import encode_pdf_date
|
||||
from PIL import Image, ImageColor, ImageDraw
|
||||
|
||||
from ocrmypdf import leptonica
|
||||
from ocrmypdf._exec import ghostscript, unpaper
|
||||
from ocrmypdf._version import PROGRAM_NAME
|
||||
from ocrmypdf._version import __version__ as VERSION
|
||||
from ocrmypdf.exceptions import (
|
||||
@@ -37,7 +38,6 @@ from ocrmypdf.exceptions import (
|
||||
PriorOcrFoundError,
|
||||
UnsupportedImageFormatError,
|
||||
)
|
||||
from ocrmypdf.exec import ghostscript, unpaper
|
||||
from ocrmypdf.helpers import Resolution, safe_symlink
|
||||
from ocrmypdf.hocrtransform import HocrTransform
|
||||
from ocrmypdf.optimize import optimize
|
||||
|
||||
@@ -27,6 +27,7 @@ from shutil import copyfileobj
|
||||
|
||||
import PIL
|
||||
|
||||
from ocrmypdf._exec import jbig2enc, pngquant, unpaper
|
||||
from ocrmypdf._unicodefun import verify_python3_env
|
||||
from ocrmypdf.exceptions import (
|
||||
BadArgsError,
|
||||
@@ -34,7 +35,6 @@ from ocrmypdf.exceptions import (
|
||||
MissingDependencyError,
|
||||
OutputFileAccessError,
|
||||
)
|
||||
from ocrmypdf.exec import jbig2enc, pngquant, unpaper
|
||||
from ocrmypdf.helpers import (
|
||||
is_file_writable,
|
||||
is_iterable_notstr,
|
||||
|
||||
@@ -19,9 +19,9 @@ import logging
|
||||
from pathlib import Path
|
||||
|
||||
from ocrmypdf import hookimpl
|
||||
from ocrmypdf._exec import ghostscript
|
||||
from ocrmypdf._validation import HOCR_OK_LANGS
|
||||
from ocrmypdf.exceptions import MissingDependencyError
|
||||
from ocrmypdf.exec import ghostscript
|
||||
from ocrmypdf.helpers import Resolution
|
||||
from ocrmypdf.subprocess import check_external_program
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ import logging
|
||||
import os
|
||||
|
||||
from ocrmypdf import hookimpl
|
||||
from ocrmypdf._exec import tesseract
|
||||
from ocrmypdf.cli import numeric
|
||||
from ocrmypdf.exceptions import MissingDependencyError
|
||||
from ocrmypdf.exec import tesseract
|
||||
from ocrmypdf.pluginspec import OcrEngine
|
||||
from ocrmypdf.subprocess import check_external_program
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ from tqdm import tqdm
|
||||
|
||||
from ocrmypdf import leptonica
|
||||
from ocrmypdf._concurrent import exec_progress_pool
|
||||
from ocrmypdf._exec import jbig2enc, pngquant
|
||||
from ocrmypdf._jobcontext import PdfContext
|
||||
from ocrmypdf.exceptions import OutputFileAccessError
|
||||
from ocrmypdf.exec import jbig2enc, pngquant
|
||||
from ocrmypdf.helpers import safe_symlink
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
+1
-1
@@ -25,8 +25,8 @@ from subprocess import PIPE, run
|
||||
import pytest
|
||||
|
||||
from ocrmypdf import api, cli, pdfinfo
|
||||
from ocrmypdf._exec import unpaper
|
||||
from ocrmypdf._plugin_manager import get_parser_options_plugins
|
||||
from ocrmypdf.exec import unpaper
|
||||
|
||||
pytest_plugins = ['helpers_namespace']
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def run_append_stderr(*args, **kwargs):
|
||||
|
||||
@hookimpl
|
||||
def generate_pdfa(pdf_pages, pdfmark, output_file, compression, pdf_version, pdfa_part):
|
||||
with patch('ocrmypdf.exec.ghostscript.run', new=run_append_stderr):
|
||||
with patch('ocrmypdf._exec.ghostscript.run', new=run_append_stderr):
|
||||
ghostscript.generate_pdfa(
|
||||
pdf_pages=pdf_pages,
|
||||
pdfmark=pdfmark,
|
||||
|
||||
@@ -39,7 +39,7 @@ def run_rig_args(args, **kwargs):
|
||||
|
||||
@hookimpl
|
||||
def generate_pdfa(pdf_pages, pdfmark, output_file, compression, pdf_version, pdfa_part):
|
||||
with patch('ocrmypdf.exec.ghostscript.run', new=run_rig_args):
|
||||
with patch('ocrmypdf._exec.ghostscript.run', new=run_rig_args):
|
||||
ghostscript.generate_pdfa(
|
||||
pdf_pages=pdf_pages,
|
||||
pdfmark=pdfmark,
|
||||
|
||||
@@ -45,7 +45,7 @@ def rasterize_pdf_page(
|
||||
rotation=None,
|
||||
filter_vector=False,
|
||||
) -> Path:
|
||||
with patch('ocrmypdf.exec.ghostscript.run', new=raise_gs_fail):
|
||||
with patch('ocrmypdf._exec.ghostscript.run', new=raise_gs_fail):
|
||||
ghostscript.rasterize_pdf_page(
|
||||
input_file=input_file,
|
||||
output_file=output_file,
|
||||
|
||||
@@ -36,7 +36,7 @@ def raise_gs_fail(*args, **kwargs):
|
||||
|
||||
@hookimpl
|
||||
def generate_pdfa(pdf_pages, pdfmark, output_file, compression, pdf_version, pdfa_part):
|
||||
with patch('ocrmypdf.exec.ghostscript.run', new=raise_gs_fail):
|
||||
with patch('ocrmypdf._exec.ghostscript.run', new=raise_gs_fail):
|
||||
ghostscript.generate_pdfa(
|
||||
pdf_pages=pdf_pages,
|
||||
pdfmark=pdfmark,
|
||||
|
||||
@@ -45,14 +45,14 @@ def bad_utf8(*args, **kwargs):
|
||||
class BadUtf8OcrEngine(TesseractOcrEngine):
|
||||
@staticmethod
|
||||
def generate_hocr(input_file, output_hocr, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=bad_utf8):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=bad_utf8):
|
||||
TesseractOcrEngine.generate_hocr(
|
||||
input_file, output_hocr, output_text, options
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_pdf(input_file, output_pdf, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=bad_utf8):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=bad_utf8):
|
||||
TesseractOcrEngine.generate_pdf(
|
||||
input_file, output_pdf, output_text, options
|
||||
)
|
||||
|
||||
@@ -38,19 +38,19 @@ def raise_size_exception(*args, **kwargs):
|
||||
class BigImageErrorOcrEngine(TesseractOcrEngine):
|
||||
@staticmethod
|
||||
def get_orientation(input_file, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_size_exception):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_size_exception):
|
||||
return TesseractOcrEngine.get_orientation(input_file, options)
|
||||
|
||||
@staticmethod
|
||||
def generate_hocr(input_file, output_hocr, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_size_exception):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_size_exception):
|
||||
TesseractOcrEngine.generate_hocr(
|
||||
input_file, output_hocr, output_text, options
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_pdf(input_file, output_pdf, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_size_exception):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_size_exception):
|
||||
TesseractOcrEngine.generate_pdf(
|
||||
input_file, output_pdf, output_text, options
|
||||
)
|
||||
|
||||
@@ -178,19 +178,19 @@ def cached_run(options, run_args, **run_kwargs):
|
||||
class CacheOcrEngine(TesseractOcrEngine):
|
||||
@staticmethod
|
||||
def get_orientation(input_file, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=partial(cached_run, options)):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=partial(cached_run, options)):
|
||||
return TesseractOcrEngine.get_orientation(input_file, options)
|
||||
|
||||
@staticmethod
|
||||
def generate_hocr(input_file, output_hocr, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=partial(cached_run, options)):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=partial(cached_run, options)):
|
||||
TesseractOcrEngine.generate_hocr(
|
||||
input_file, output_hocr, output_text, options
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_pdf(input_file, output_pdf, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=partial(cached_run, options)):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=partial(cached_run, options)):
|
||||
TesseractOcrEngine.generate_pdf(
|
||||
input_file, output_pdf, output_text, options
|
||||
)
|
||||
|
||||
@@ -41,19 +41,19 @@ def raise_crash(*args, **kwargs):
|
||||
class CrashOcrEngine(TesseractOcrEngine):
|
||||
@staticmethod
|
||||
def get_orientation(input_file, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_crash):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_crash):
|
||||
return TesseractOcrEngine.get_orientation(input_file, options)
|
||||
|
||||
@staticmethod
|
||||
def generate_hocr(input_file, output_hocr, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_crash):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_crash):
|
||||
TesseractOcrEngine.generate_hocr(
|
||||
input_file, output_hocr, output_text, options
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def generate_pdf(input_file, output_pdf, output_text, options):
|
||||
with patch('ocrmypdf.exec.tesseract.run', new=raise_crash):
|
||||
with patch('ocrmypdf._exec.tesseract.run', new=raise_crash):
|
||||
TesseractOcrEngine.generate_pdf(
|
||||
input_file, output_pdf, output_text, options
|
||||
)
|
||||
|
||||
@@ -22,8 +22,8 @@ import pikepdf
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf._exec.ghostscript import rasterize_pdf
|
||||
from ocrmypdf.exceptions import ExitCode
|
||||
from ocrmypdf.exec.ghostscript import rasterize_pdf
|
||||
from ocrmypdf.helpers import Resolution
|
||||
|
||||
check_ocrmypdf = pytest.helpers.check_ocrmypdf
|
||||
|
||||
@@ -21,7 +21,7 @@ import pytest
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf import hocrtransform
|
||||
from ocrmypdf.exec.tesseract import HOCR_TEMPLATE
|
||||
from ocrmypdf._exec.tesseract import HOCR_TEMPLATE
|
||||
from ocrmypdf.helpers import check_pdf
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
+1
-1
@@ -28,8 +28,8 @@ import pytest
|
||||
from PIL import Image
|
||||
|
||||
import ocrmypdf
|
||||
from ocrmypdf._exec import ghostscript, tesseract
|
||||
from ocrmypdf.exceptions import ExitCode, MissingDependencyError
|
||||
from ocrmypdf.exec import ghostscript, tesseract
|
||||
from ocrmypdf.pdfa import file_claims_pdfa
|
||||
from ocrmypdf.pdfinfo import Colorspace, Encoding, PdfInfo
|
||||
from ocrmypdf.subprocess import get_version
|
||||
|
||||
@@ -23,8 +23,8 @@ import pytest
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf import optimize as opt
|
||||
from ocrmypdf.exec import jbig2enc, pngquant
|
||||
from ocrmypdf.exec.ghostscript import rasterize_pdf
|
||||
from ocrmypdf._exec import jbig2enc, pngquant
|
||||
from ocrmypdf._exec.ghostscript import rasterize_pdf
|
||||
from ocrmypdf.helpers import Resolution
|
||||
|
||||
check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=e1101
|
||||
|
||||
@@ -26,7 +26,7 @@ from PIL import Image
|
||||
from reportlab.pdfgen.canvas import Canvas
|
||||
|
||||
from ocrmypdf import pdfinfo
|
||||
from ocrmypdf.exec import ghostscript
|
||||
from ocrmypdf._exec import ghostscript
|
||||
from ocrmypdf.pdfinfo import Colorspace, Encoding
|
||||
|
||||
# pylint: disable=protected-access
|
||||
|
||||
@@ -20,7 +20,7 @@ from math import isclose
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf.exec import ghostscript
|
||||
from ocrmypdf._exec import ghostscript
|
||||
from ocrmypdf.helpers import Resolution
|
||||
from ocrmypdf.leptonica import Pix
|
||||
from ocrmypdf.pdfinfo import PdfInfo
|
||||
|
||||
@@ -26,7 +26,7 @@ import pytest
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf import leptonica
|
||||
from ocrmypdf.exec import ghostscript, tesseract
|
||||
from ocrmypdf._exec import ghostscript, tesseract
|
||||
from ocrmypdf.helpers import Resolution
|
||||
from ocrmypdf.pdfinfo import PdfInfo
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from ocrmypdf import pdfinfo
|
||||
from ocrmypdf._exec import tesseract
|
||||
from ocrmypdf.exceptions import MissingDependencyError
|
||||
from ocrmypdf.exec import tesseract
|
||||
|
||||
# pylint: disable=no-member,redefined-outer-name
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def test_no_unpaper(resources, no_outpdf):
|
||||
output = fspath(no_outpdf)
|
||||
|
||||
_parser, options, pm = get_parser_options_plugins(["--clean", input_, output])
|
||||
with patch("ocrmypdf.exec.unpaper.version") as mock_unpaper_version:
|
||||
with patch("ocrmypdf._exec.unpaper.version") as mock_unpaper_version:
|
||||
mock_unpaper_version.side_effect = FileNotFoundError("unpaper")
|
||||
|
||||
with pytest.raises(MissingDependencyError):
|
||||
@@ -51,7 +51,7 @@ def test_old_unpaper(resources, no_outpdf):
|
||||
output = fspath(no_outpdf)
|
||||
|
||||
_parser, options, pm = get_parser_options_plugins(["--clean", input_, output])
|
||||
with patch("ocrmypdf.exec.unpaper.version") as mock_unpaper_version:
|
||||
with patch("ocrmypdf._exec.unpaper.version") as mock_unpaper_version:
|
||||
mock_unpaper_version.return_value = '0.5'
|
||||
|
||||
with pytest.raises(MissingDependencyError):
|
||||
|
||||
@@ -56,27 +56,27 @@ def test_hocr_notlatin_warning(caplog):
|
||||
|
||||
|
||||
def test_old_ghostscript(caplog):
|
||||
with patch('ocrmypdf.exec.ghostscript.version', return_value='9.19'), patch(
|
||||
'ocrmypdf.exec.tesseract.has_textonly_pdf', return_value=True
|
||||
with patch('ocrmypdf._exec.ghostscript.version', return_value='9.19'), patch(
|
||||
'ocrmypdf._exec.tesseract.has_textonly_pdf', return_value=True
|
||||
):
|
||||
vd.check_options(*make_opts_pm(language='chi_sim', output_type='pdfa'))
|
||||
assert 'Ghostscript does not work correctly' in caplog.text
|
||||
|
||||
with patch('ocrmypdf.exec.ghostscript.version', return_value='9.18'), patch(
|
||||
'ocrmypdf.exec.tesseract.has_textonly_pdf', return_value=True
|
||||
with patch('ocrmypdf._exec.ghostscript.version', return_value='9.18'), patch(
|
||||
'ocrmypdf._exec.tesseract.has_textonly_pdf', return_value=True
|
||||
):
|
||||
with pytest.raises(MissingDependencyError):
|
||||
vd.check_options(*make_opts_pm(output_type='pdfa-3'))
|
||||
|
||||
with patch('ocrmypdf.exec.ghostscript.version', return_value='9.24'), patch(
|
||||
'ocrmypdf.exec.tesseract.has_textonly_pdf', return_value=True
|
||||
with patch('ocrmypdf._exec.ghostscript.version', return_value='9.24'), patch(
|
||||
'ocrmypdf._exec.tesseract.has_textonly_pdf', return_value=True
|
||||
):
|
||||
with pytest.raises(MissingDependencyError):
|
||||
vd.check_options(*make_opts_pm())
|
||||
|
||||
|
||||
def test_old_tesseract_error():
|
||||
with patch('ocrmypdf.exec.tesseract.has_textonly_pdf', return_value=False):
|
||||
with patch('ocrmypdf._exec.tesseract.has_textonly_pdf', return_value=False):
|
||||
with pytest.raises(MissingDependencyError):
|
||||
opts = make_opts(pdf_renderer='sandwich', language='eng')
|
||||
plugin_manager = get_plugin_manager(opts.plugins)
|
||||
@@ -107,13 +107,13 @@ def test_optimizing(caplog):
|
||||
|
||||
|
||||
def test_user_words(caplog):
|
||||
with patch('ocrmypdf.exec.tesseract.has_user_words', return_value=False):
|
||||
with patch('ocrmypdf._exec.tesseract.has_user_words', return_value=False):
|
||||
opts = make_opts(user_words='foo')
|
||||
plugin_manager = get_plugin_manager(opts.plugins)
|
||||
vd.check_options(opts, plugin_manager)
|
||||
assert '4.0 ignores --user-words' in caplog.text
|
||||
caplog.clear()
|
||||
with patch('ocrmypdf.exec.tesseract.has_user_words', return_value=True):
|
||||
with patch('ocrmypdf._exec.tesseract.has_user_words', return_value=True):
|
||||
opts = make_opts(user_patterns='foo')
|
||||
plugin_manager = get_plugin_manager(opts.plugins)
|
||||
vd.check_options(opts, plugin_manager)
|
||||
|
||||
Reference in New Issue
Block a user