Skip to content

Commit 23357ca

Browse files
fix: restore PDF test scenarios and fail-loudly imports
- Restore PDF files and expected records in simple_unstructured_scenario and no_file_extension_unstructured_scenario - Remove all try/except guards: imports fail loudly per maintainer direction - Move _import_unstructured() call to _read_file_locally() only (not needed for API path) - Add 'pdf' extra to unstructured dependency in pyproject.toml - Update corrupted file error message to match real pdfminer error - Update poetry.lock Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent 6e23fab commit 23357ca

4 files changed

Lines changed: 5484 additions & 3400 deletions

File tree

airbyte_cdk/sources/file_based/file_types/unstructured_parser.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,19 @@ def optional_decode(contents: Union[str, bytes]) -> str:
7474

7575

7676
def _import_unstructured() -> None:
77-
"""Dynamically imported as needed, due to slow import speed.
78-
79-
DOCX and PPTX are declared extras (`unstructured[docx, pptx]`) and will
80-
fail loudly if missing. PDF requires heavy optional deps (`torch`,
81-
`unstructured-inference`) that connectors must opt into by installing
82-
`unstructured[pdf]`, so its import is the only one guarded.
83-
"""
77+
"""Dynamically imported as needed, due to slow import speed."""
8478
global unstructured_partition_pdf
8579
global unstructured_partition_docx
8680
global unstructured_partition_pptx
8781

8882
from unstructured.partition.docx import partition_docx
83+
from unstructured.partition.pdf import partition_pdf
8984
from unstructured.partition.pptx import partition_pptx
9085

9186
unstructured_partition_docx = partition_docx
87+
unstructured_partition_pdf = partition_pdf
9288
unstructured_partition_pptx = partition_pptx
9389

94-
try:
95-
from unstructured.partition.pdf import partition_pdf
96-
97-
unstructured_partition_pdf = partition_pdf
98-
except ImportError:
99-
logging.debug("PDF partition module unavailable; install unstructured[pdf] to enable.")
100-
10190

10291
def user_error(e: Exception) -> bool:
10392
"""
@@ -211,8 +200,6 @@ def _read_file(
211200
format: UnstructuredFormat,
212201
logger: logging.Logger,
213202
) -> str:
214-
_import_unstructured()
215-
216203
filetype: FileType | None = self._get_filetype(file_handle, remote_file)
217204

218205
if filetype is None or filetype not in self._supported_file_types():
@@ -364,19 +351,13 @@ def _read_file_locally(
364351

365352
try:
366353
if filetype == FileType.PDF:
367-
if not unstructured_partition_pdf:
368-
raise ImportError("PDF partition dependencies are not installed")
369354
file_handle.seek(0)
370355
with BytesIO(file_handle.read()) as file:
371356
file_handle.seek(0)
372357
elements = unstructured_partition_pdf(file=file, strategy=strategy)
373358
elif filetype == FileType.DOCX:
374-
if not unstructured_partition_docx:
375-
raise ImportError("DOCX partition dependencies are not installed")
376359
elements = unstructured_partition_docx(file=file)
377360
elif filetype == FileType.PPTX:
378-
if not unstructured_partition_pptx:
379-
raise ImportError("PPTX partition dependencies are not installed")
380361
elements = unstructured_partition_pptx(file=file)
381362
except Exception as e:
382363
raise self._create_parse_error(remote_file, str(e))

0 commit comments

Comments
 (0)