aeat.core._optional_extras module¶
Capability-gated optional package extras and their import guard.
The shipped package is lean: a bare pip install aeat omits the optional
integration stacks (Google export, the live-AEAT browser, the Anthropic-API LLM
provider). Each maps to a [project.optional-dependencies] extra and is
imported lazily, so the core CLI builds and runs without it.
This module is the single source of truth for those extras. It lives in core
— the innermost layer — so an adapter can guard its own external-library import
without importing the application layer, and the application doctor can probe the
same OPTIONAL_EXTRAS registry through
application.provisioning.probe_optional_extra(). require_optional_extra()
is the seam every feature boundary calls before its lazy import so a missing
extra becomes one instructive MissingOptionalExtraError naming
pip install aeat-cli[<extra>] instead of a raw deep-stack
ModuleNotFoundError.
These records describe package availability only. They do not decide whether an
operator has opted into Google export, browser automation, or hosted LLM usage;
that consent surface is represented separately by ServiceCapability.
- class OptionalExtra(**data)[source]¶
Bases:
BaseModelA capability-gated optional package extra and how to probe/install it.
- Variables:
extra – The
[project.optional-dependencies]key.import_name – Importable package/module name used by the spec-only probe.
feature – Human-readable feature label used in refusals and doctor rows.
- Parameters:
- extra: str¶
- import_name: str¶
- feature: str¶
- exception MissingOptionalExtraError(extra)[source]¶
Bases:
CoreError,ImportErrorRaised when a feature is reached but its optional extra is not installed.
Descends from
CoreErrorso the project-wideAeatErrorboundary sees the refusal, and fromImportErrorso adapters that already catch import failures keep working. Application probes report the same missing package as aapplication.provisioning.DependencyStatus; feature guards raise this exception only when the operator reaches the guarded boundary.- Variables:
extra – Optional-extra registry record that failed the spec-only probe.
install_hint – Exact
pip install aeat-cli[<extra>]remediation command.
- Parameters:
extra (OptionalExtra)
- Return type:
None
- code: ClassVar[ErrorCode]¶
- optional_extra_available(extra)[source]¶
Return whether
extra’s package is importable, without importing it.A spec-only check (
importlib.util.find_spec()) — no side effects, no heavy module load. Never raises: a missing parent package resolves toFalse. This helper intentionally does not callrequire_optional_extra(); probes should report dependency status, not raise feature-boundary refusals.- Parameters:
extra (
OptionalExtra) – TheOptionalExtraregistry record to probe.- Return type:
- Returns:
Truewhenextra.import_namehas an import spec; otherwiseFalse.
- require_optional_extra(extra)[source]¶
Raise
MissingOptionalExtraErrorwhenextrais absent; a no-op when present.Call this at a feature boundary, immediately before the lazy import of the extra’s package, so a missing extra becomes a single actionable message instead of a raw deep-stack
ModuleNotFoundError.- Parameters:
extra (
OptionalExtra) – TheOptionalExtrarequired by the feature boundary.- Raises:
MissingOptionalExtraError – If
extra.import_nameis not importable.- Return type: