component_framework.adapters
Adapter helpers for optional framework extras.
1"""Adapter helpers for optional framework extras.""" 2 3 4def _require_extra(package: str, extra: str) -> ImportError: 5 """Return an ImportError with an actionable install hint for a missing optional extra. 6 7 Call this inside an ``except ImportError`` block and raise the result with ``from e`` 8 to preserve the original exception chain:: 9 10 try: 11 from fastapi import Request 12 except ImportError as e: 13 from . import _require_extra 14 raise _require_extra("fastapi", "fastapi") from e 15 16 Args: 17 package: The missing package name (e.g. ``"fastapi"``). 18 extra: The extras group that installs it (e.g. ``"fastapi"``). 19 20 Returns: 21 ImportError: Always, with an actionable pip install hint. 22 """ 23 return ImportError( 24 f"'{package}' is not installed. " 25 f"Install the '{extra}' extra: pip install 'component-framework[{extra}]'" 26 )