Fix ruff linting issues
- Use X | Y syntax in isinstance calls (UP038) - Remove trailing whitespace from blank lines (W293)
This commit is contained in:
@@ -357,7 +357,7 @@ class OCROptions(BaseModel):
|
||||
if isinstance(value, Path):
|
||||
return {'__type__': 'Path', 'value': str(value)}
|
||||
elif (
|
||||
isinstance(value, (BinaryIO, IOBase))
|
||||
isinstance(value, BinaryIO | IOBase)
|
||||
or hasattr(value, 'read')
|
||||
or hasattr(value, 'write')
|
||||
):
|
||||
@@ -369,7 +369,7 @@ class OCROptions(BaseModel):
|
||||
elif isinstance(value, property):
|
||||
# Handle property objects that shouldn't be serialized
|
||||
return None
|
||||
elif isinstance(value, (list, tuple)):
|
||||
elif isinstance(value, list | tuple):
|
||||
return [_serialize_value(item) for item in value]
|
||||
elif isinstance(value, dict):
|
||||
return {k: _serialize_value(v) for k, v in value.items()}
|
||||
|
||||
@@ -123,11 +123,11 @@ def _check_plugin_invariant_options(options: OCROptions) -> None:
|
||||
def _check_plugin_options(options: OCROptions, plugin_manager: PluginManager) -> None:
|
||||
# First, let plugins check their external dependencies
|
||||
plugin_manager.hook.check_options(options=options)
|
||||
|
||||
|
||||
# Then check OCR engine language support
|
||||
ocr_engine_languages = plugin_manager.hook.get_ocr_engine().languages(options)
|
||||
check_options_languages(options, ocr_engine_languages)
|
||||
|
||||
|
||||
# Finally, run comprehensive validation using the coordinator
|
||||
from ocrmypdf._validation_coordinator import ValidationCoordinator
|
||||
coordinator = ValidationCoordinator(plugin_manager)
|
||||
@@ -136,7 +136,7 @@ def _check_plugin_options(options: OCROptions, plugin_manager: PluginManager) ->
|
||||
|
||||
def check_options(options: OCROptions, plugin_manager: PluginManager) -> None:
|
||||
"""Check options for validity and consistency.
|
||||
|
||||
|
||||
This function coordinates validation across the entire system:
|
||||
1. Core validation (platform, files, preprocessing)
|
||||
2. Plugin external dependency validation
|
||||
|
||||
@@ -26,12 +26,12 @@ class ValidationCoordinator:
|
||||
|
||||
def validate_all_options(self, options: OCROptions) -> None:
|
||||
"""Run comprehensive validation on all options.
|
||||
|
||||
|
||||
This runs validation in the correct order:
|
||||
1. Plugin self-validation (already done by Pydantic)
|
||||
2. Plugin context validation (requires external context)
|
||||
3. Cross-cutting validation (between plugins and core)
|
||||
|
||||
|
||||
Args:
|
||||
options: The options to validate
|
||||
"""
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ def setup_plugin_infrastructure(
|
||||
|
||||
if not plugins:
|
||||
plugins = []
|
||||
elif isinstance(plugins, (str, Path)):
|
||||
elif isinstance(plugins, str | Path):
|
||||
plugins = [plugins]
|
||||
else:
|
||||
plugins = list(plugins)
|
||||
|
||||
@@ -10,7 +10,7 @@ from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from ocrmypdf import Executor, PdfContext, hookimpl
|
||||
from ocrmypdf._exec import jbig2enc, pngquant
|
||||
@@ -18,7 +18,6 @@ from ocrmypdf._pipeline import get_pdf_save_settings
|
||||
from ocrmypdf.cli import numeric
|
||||
from ocrmypdf.optimize import optimize
|
||||
from ocrmypdf.subprocess import check_external_program
|
||||
from pydantic import model_validator
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ class TesseractOptions(BaseModel):
|
||||
|
||||
def validate_with_context(self, languages: list[str]) -> None:
|
||||
"""Validate options that require external context.
|
||||
|
||||
|
||||
Args:
|
||||
languages: List of languages being used for OCR
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user