diff --git a/src/ocrmypdf/_pipeline.py b/src/ocrmypdf/_pipeline.py index 182a2888..142c2983 100644 --- a/src/ocrmypdf/_pipeline.py +++ b/src/ocrmypdf/_pipeline.py @@ -194,7 +194,7 @@ def validate_pdfinfo_options(context): "form and all filled form fields. The output PDF will be " "'flattened' and will no longer be fillable." ) - context.plugin_manager.hook.prepare(options=options) + context.plugin_manager.hook.validate(pdfinfo=pdfinfo, options=options) def get_page_dpi(pageinfo, options): diff --git a/src/ocrmypdf/_plugin_manager.py b/src/ocrmypdf/_plugin_manager.py index a7f7987e..2c3df5a1 100644 --- a/src/ocrmypdf/_plugin_manager.py +++ b/src/ocrmypdf/_plugin_manager.py @@ -1,3 +1,20 @@ +# © 2020 James R. Barlow: github.com/jbarlow83 +# +# This file is part of OCRmyPDF. +# +# OCRmyPDF is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# OCRmyPDF is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OCRmyPDF. If not, see . + import importlib import pluggy diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index 6f21bb09..1691eb00 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -320,6 +320,8 @@ def run_pipeline(options, api=False): options, ) + pm.hook.prepare(options=options) + # Gather pdfinfo and create context pdfinfo = get_pdfinfo( origin_pdf, diff --git a/src/ocrmypdf/example.py b/src/ocrmypdf/example.py index 755e0f57..dda37bf0 100644 --- a/src/ocrmypdf/example.py +++ b/src/ocrmypdf/example.py @@ -1,11 +1,20 @@ +import logging + from ocrmypdf import hookimpl +log = logging.getLogger(__name__) + @hookimpl def prepare(options): pass +@hookimpl +def validate(pdfinfo, options): + pass + + @hookimpl def filter_ocr_image(image): return image diff --git a/src/ocrmypdf/pluginspec.py b/src/ocrmypdf/pluginspec.py index c3aac6f2..86657c9d 100644 --- a/src/ocrmypdf/pluginspec.py +++ b/src/ocrmypdf/pluginspec.py @@ -33,13 +33,6 @@ def prepare(options: Namespace) -> None: The plugin may modify the options. All objects that are in options must be picklable so they can be marshalled to child worker processes. - - Typically, a plugin will call ``registry.register_plugin(__name__)`` to register - all of its public functions with the plugin registry. Functions that are - not intended for registration should be prefixed with an underscore. - Functions that imported from other modules will be ignored by - ``.register_plugin()``. For example if you use ``from os import basename``, - ``basename`` will not be registered. """ @@ -57,7 +50,7 @@ def validate(pdfinfo: PdfInfo, options: Namespace) -> None: """ -@hookspec +@hookspec(firstresult=True) def filter_ocr_image(image: Image) -> Image: """Called to filter the image before it is sent to OCR.