Skip to content

Commit 5a5044d

Browse files
refactor: use normal imports for docx/pptx, keep only pdf guarded
DOCX and PPTX are declared extras so their imports should always succeed. Only PDF needs a guarded import since it requires heavy optional deps (torch, unstructured-inference) not shipped with the CDK. Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent 158d1d4 commit 5a5044d

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

airbyte_cdk/sources/file_based/file_types/unstructured_parser.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,27 @@ def optional_decode(contents: Union[str, bytes]) -> str:
7676
def _import_unstructured() -> None:
7777
"""Dynamically imported as needed, due to slow import speed.
7878
79-
Each partition module is imported individually so that a missing optional
80-
dependency (e.g. `pi_heif` for PDF) does not block the modules that *are*
81-
available. Callers check the global sentinels before use.
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.
8283
"""
8384
global unstructured_partition_pdf
8485
global unstructured_partition_docx
8586
global unstructured_partition_pptx
86-
try:
87-
from unstructured.partition.docx import partition_docx
8887

89-
unstructured_partition_docx = partition_docx
90-
except ImportError:
91-
logging.debug("DOCX partition module unavailable; DOCX parsing will be disabled.")
92-
try:
93-
from unstructured.partition.pptx import partition_pptx
88+
from unstructured.partition.docx import partition_docx
89+
from unstructured.partition.pptx import partition_pptx
90+
91+
unstructured_partition_docx = partition_docx
92+
unstructured_partition_pptx = partition_pptx
9493

95-
unstructured_partition_pptx = partition_pptx
96-
except ImportError:
97-
logging.debug("PPTX partition module unavailable; PPTX parsing will be disabled.")
9894
try:
9995
from unstructured.partition.pdf import partition_pdf
10096

10197
unstructured_partition_pdf = partition_pdf
10298
except ImportError:
103-
logging.debug("PDF partition module unavailable; PDF parsing will be disabled.")
99+
logging.debug("PDF partition module unavailable; install unstructured[pdf] to enable.")
104100

105101

106102
def user_error(e: Exception) -> bool:

0 commit comments

Comments
 (0)