refactor: update pipeline entry points to use OCROptions directly
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import logging.handlers
|
||||
from collections.abc import Sequence
|
||||
@@ -19,6 +18,7 @@ import PIL
|
||||
from ocrmypdf._concurrent import Executor
|
||||
from ocrmypdf._graft import OcrGrafter
|
||||
from ocrmypdf._jobcontext import PageContext, PdfContext
|
||||
from ocrmypdf._options import OCROptions
|
||||
from ocrmypdf._pipeline import (
|
||||
copy_final,
|
||||
is_ocr_required,
|
||||
@@ -48,21 +48,6 @@ from ocrmypdf._validation import (
|
||||
check_requested_output_file,
|
||||
create_input_file,
|
||||
)
|
||||
|
||||
|
||||
def _convert_pages_field_for_legacy_compatibility(options: argparse.Namespace) -> None:
|
||||
"""Convert pages field from string to set if needed.
|
||||
|
||||
This is a temporary shim to handle the transition from CLI string processing
|
||||
to OCROptions Pydantic validation. The pages field needs to be converted
|
||||
before calling do_get_pdfinfo() since PdfInfo expects a Container[int].
|
||||
|
||||
TODO: Remove this function when the refactoring plan is complete and all
|
||||
pipeline functions work directly with OCROptions instead of Namespace.
|
||||
"""
|
||||
if hasattr(options, 'pages') and isinstance(options.pages, str):
|
||||
from ocrmypdf._options import _pages_from_ranges
|
||||
options.pages = _pages_from_ranges(options.pages)
|
||||
from ocrmypdf.exceptions import ExitCode
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -170,7 +155,7 @@ def exec_concurrent(context: PdfContext, executor: Executor) -> Sequence[str]:
|
||||
|
||||
|
||||
def _run_pipeline(
|
||||
options: argparse.Namespace,
|
||||
options: OCROptions,
|
||||
plugin_manager: OcrmypdfPluginManager,
|
||||
) -> ExitCode:
|
||||
with (
|
||||
@@ -190,9 +175,6 @@ def _run_pipeline(
|
||||
original_filename, start_input_file, work_folder / 'origin.pdf', options
|
||||
)
|
||||
|
||||
# Convert pages field if needed before gathering pdfinfo
|
||||
_convert_pages_field_for_legacy_compatibility(options)
|
||||
|
||||
# Gather pdfinfo and create context
|
||||
pdfinfo = do_get_pdfinfo(origin_pdf, executor, options)
|
||||
context = PdfContext(options, work_folder, origin_pdf, pdfinfo, plugin_manager)
|
||||
@@ -208,14 +190,14 @@ def _run_pipeline(
|
||||
|
||||
|
||||
def run_pipeline_cli(
|
||||
options: argparse.Namespace,
|
||||
options: OCROptions,
|
||||
*,
|
||||
plugin_manager: OcrmypdfPluginManager,
|
||||
) -> ExitCode:
|
||||
"""Run the OCR pipeline with command line exception handling.
|
||||
|
||||
Args:
|
||||
options: The parsed command line options.
|
||||
options: The parsed OCR options.
|
||||
plugin_manager: The plugin manager to use. If not provided, one will be
|
||||
created.
|
||||
"""
|
||||
@@ -223,14 +205,14 @@ def run_pipeline_cli(
|
||||
|
||||
|
||||
def run_pipeline(
|
||||
options: argparse.Namespace,
|
||||
options: OCROptions,
|
||||
*,
|
||||
plugin_manager: OcrmypdfPluginManager,
|
||||
) -> ExitCode:
|
||||
"""Run the OCR pipeline without command line exception handling.
|
||||
|
||||
Args:
|
||||
options: The parsed command line options.
|
||||
options: The parsed OCR options.
|
||||
plugin_manager: The plugin manager to use. If not provided, one will be
|
||||
created.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user