From 16990890d8c285ac250d73a4cce552706efb9864 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 12 Jun 2019 17:52:25 -0700 Subject: [PATCH] Remove "from ocrmypdf import ocrmypdf" Messes up future imports from ocrmypdf, so don't do it. --- docs/api.rst | 10 +++++----- src/ocrmypdf/__init__.py | 2 +- src/ocrmypdf/api.py | 2 +- tests/test_filters.py | 4 ++-- tests/test_main.py | 6 ++++-- tests/test_page_numbers.py | 4 ++-- tests/test_weave.py | 6 +++--- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index d4aeeca5..32efd3be 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -12,9 +12,9 @@ OCRmyPDF one high-level function to run its main engine from an application. The .. code-block:: python - from ocrmypdf import ocrmypdf + import ocrmypdf - ocrmypdf('input.pdf', 'output.pdf', deskew=True) + ocrmypdf.run('input.pdf', 'output.pdf', deskew=True) With a few exceptions, all of the command line arguments are available and may be passed as equivalent keywords. @@ -29,11 +29,11 @@ The :func:`ocrmypdf.ocrmypdf` function runs OCRmyPDF similar to command line exe - manage the signal flags of worker processes 0 execute other subprocesses (forking and executing other programs) -The Python process that calls ``ocrmypdf()`` must be sufficiently privileged to perform these actions. If it is not, ``ocrmypdf()`` will fail. +The Python process that calls ``ocrmypdf.run()`` must be sufficiently privileged to perform these actions. If it is not, ``ocrmypdf()`` will fail. There is no currently no option to manage how jobs are scheduled other than the argument ``jobs=`` which will limit the number of worker processes. -Forking a child process to call ``ocrmypdf()`` is suggested. That way your application will survive even if OCRmyPDF does not. +Forking a child process to call ``ocrmypdf.run()`` is suggested. That way your application will survive even if OCRmyPDF does not. Logging ^^^^^^^ @@ -59,7 +59,7 @@ When OCRmyPDF succeeds conditionally, it may return an integer exit code. Reference --------- -.. autofunction:: ocrmypdf.ocrmypdf +.. autofunction:: ocrmypdf.run .. autoclass:: ocrmypdf.Verbosity :members: diff --git a/src/ocrmypdf/__init__.py b/src/ocrmypdf/__init__.py index 29491ca9..00d757cf 100644 --- a/src/ocrmypdf/__init__.py +++ b/src/ocrmypdf/__init__.py @@ -44,4 +44,4 @@ from . import hocrtransform from . import leptonica from . import pdfa from . import pdfinfo -from .api import ocrmypdf, configure_logging, Verbosity +from .api import run, configure_logging, Verbosity diff --git a/src/ocrmypdf/api.py b/src/ocrmypdf/api.py index eaad44f9..94c3c6d3 100644 --- a/src/ocrmypdf/api.py +++ b/src/ocrmypdf/api.py @@ -158,7 +158,7 @@ def create_options(*, input_file, output_file, **kwargs): return options -def ocrmypdf( # pylint: disable=unused-argument +def run( # pylint: disable=unused-argument input_file, output_file, *, diff --git a/tests/test_filters.py b/tests/test_filters.py index 89c34a25..5d9482ea 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -21,7 +21,7 @@ from PIL import Image import pytest -from ocrmypdf import ocrmypdf +import ocrmypdf from ocrmypdf.filters import invert, whiteout from ocrmypdf._plugins import load_plugin @@ -80,7 +80,7 @@ def test_filter_from_cmdline(resources, outdir): def test_filter_from_api(resources, outdir): - ocrmypdf( + ocrmypdf.run( resources / 'crom.png', outdir / 'out.pdf', image_dpi=100, diff --git a/tests/test_main.py b/tests/test_main.py index 86f52b21..7e2693e4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -27,7 +27,7 @@ import PIL import pytest from PIL import Image -from ocrmypdf import ocrmypdf +import ocrmypdf from ocrmypdf.exceptions import ExitCode, MissingDependencyError from ocrmypdf.exec import ghostscript, qpdf, tesseract from ocrmypdf.leptonica import Pix @@ -614,7 +614,9 @@ def test_closed_streams(spoof_tesseract_noop, ocrmypdf_exec, resources, outpdf): def test_masks(spoof_tesseract_noop, resources, outpdf): assert ( - ocrmypdf(resources / 'masks.pdf', outpdf, tesseract_env=spoof_tesseract_noop) + ocrmypdf.run( + resources / 'masks.pdf', outpdf, tesseract_env=spoof_tesseract_noop + ) == ExitCode.ok ) diff --git a/tests/test_page_numbers.py b/tests/test_page_numbers.py index a870a987..a2bc9f4d 100644 --- a/tests/test_page_numbers.py +++ b/tests/test_page_numbers.py @@ -17,7 +17,7 @@ import pytest -from ocrmypdf import ocrmypdf as run +import ocrmypdf from ocrmypdf._validation import _pages_from_ranges from ocrmypdf.pdfinfo import PdfInfo @@ -42,7 +42,7 @@ def test_list_range(): def test_limited_pages(resources, outpdf, spoof_tesseract_cache): multi = resources / 'multipage.pdf' - run( + ocrmypdf.run( multi, outpdf, pages='5-6', diff --git a/tests/test_weave.py b/tests/test_weave.py index 5c72a8fc..cd181877 100644 --- a/tests/test_weave.py +++ b/tests/test_weave.py @@ -19,7 +19,7 @@ import os import pytest -from ocrmypdf import ocrmypdf +import ocrmypdf import pikepdf os_environ = pytest.helpers.os_environ @@ -36,14 +36,14 @@ def test_no_glyphless_weave(resources, outdir): env = os.environ.copy() env['_OCRMYPDF_MAX_REPLACE_PAGES'] = '2' with os_environ(env): - ocrmypdf( + ocrmypdf.run( outdir / 'test.pdf', outdir / 'out.pdf', deskew=True, tesseract_timeout=0 ) @pytest.helpers.needs_pdfminer def test_links(resources, outpdf): - ocrmypdf( + ocrmypdf.run( resources / 'link.pdf', outpdf, redo_ocr=True, oversample=200, output_type='pdf' ) pdf = pikepdf.open(outpdf)