fix: ensure pickling compatibility for OCROptions in multiprocessing
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -38,10 +38,10 @@ class PdfContext:
|
||||
# Accept both types during transition
|
||||
if isinstance(options, Namespace):
|
||||
self.options = OCROptions.from_namespace(options)
|
||||
self._legacy_options = options
|
||||
self._namespace_options = options # Keep original for PageContext
|
||||
else:
|
||||
self.options = options
|
||||
self._legacy_options = None
|
||||
self._namespace_options = options.to_namespace() # Convert immediately for PageContext
|
||||
self.work_folder = work_folder
|
||||
self.origin = origin
|
||||
self.pdfinfo = pdfinfo
|
||||
@@ -50,9 +50,7 @@ class PdfContext:
|
||||
@property
|
||||
def legacy_options(self) -> Namespace:
|
||||
"""Provide Namespace for plugin compatibility."""
|
||||
if self._legacy_options is None:
|
||||
self._legacy_options = self.options.to_namespace()
|
||||
return self._legacy_options
|
||||
return self._namespace_options
|
||||
|
||||
def get_path(self, name: str) -> Path:
|
||||
"""Generate a ``Path`` for an intermediate file involved in processing.
|
||||
@@ -91,11 +89,8 @@ class PageContext:
|
||||
def __init__(self, pdf_context: PdfContext, pageno):
|
||||
self.work_folder = pdf_context.work_folder
|
||||
self.origin = pdf_context.origin
|
||||
# Always use the legacy options for PageContext to ensure pickling works
|
||||
if hasattr(pdf_context.options, 'to_namespace'):
|
||||
self.options = pdf_context.options.to_namespace()
|
||||
else:
|
||||
self.options = pdf_context.options
|
||||
# Always use Namespace for PageContext to avoid pickling issues
|
||||
self.options = pdf_context._namespace_options
|
||||
self.pageno = pageno
|
||||
self.pageinfo = pdf_context.pdfinfo[pageno]
|
||||
self.plugin_manager = pdf_context.plugin_manager
|
||||
@@ -111,12 +106,7 @@ class PageContext:
|
||||
def __getstate__(self):
|
||||
state = self.__dict__.copy()
|
||||
|
||||
# Convert OCROptions to Namespace for pickling compatibility
|
||||
if hasattr(state['options'], 'to_namespace'):
|
||||
state['options'] = state['options'].to_namespace()
|
||||
else:
|
||||
state['options'] = copy(state['options'])
|
||||
|
||||
state['options'] = copy(self.options)
|
||||
# Handle stream inputs
|
||||
if hasattr(state['options'], 'input_file'):
|
||||
if not isinstance(state['options'].input_file, str | bytes | os.PathLike):
|
||||
|
||||
Reference in New Issue
Block a user