|
| 1 | +"""Fail fast with a clear error on a skewed/incomplete agentex-client install |
| 2 | +instead of a cryptic `cannot import name ... from agentex.types`.""" |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +from importlib.metadata import PackageNotFoundError, version |
| 7 | + |
| 8 | + |
| 9 | +def _installed(package: str) -> str | None: |
| 10 | + try: |
| 11 | + return version(package) |
| 12 | + except PackageNotFoundError: |
| 13 | + return None |
| 14 | + |
| 15 | + |
| 16 | +def verify_client_compatibility() -> None: |
| 17 | + sdk, client = _installed("agentex-sdk"), _installed("agentex-client") |
| 18 | + |
| 19 | + # Published in lockstep — a version mismatch means a skewed client (floor |
| 20 | + # pins can be bypassed by frozen locks, --no-deps, or pre-built images). |
| 21 | + if sdk and client and sdk != client: |
| 22 | + raise ImportError( |
| 23 | + f"agentex-sdk {sdk} requires the co-released agentex-client {sdk}, but " |
| 24 | + f"agentex-client {client} is installed — reinstall both at the same " |
| 25 | + f"version (`pip install --force-reinstall agentex-sdk`)." |
| 26 | + ) |
| 27 | + |
| 28 | + # Surface canary: a partial install can leave the client REST surface |
| 29 | + # incomplete even when versions match. `Event` went missing in the incident. |
| 30 | + try: |
| 31 | + from agentex.types import Event as _Event # noqa: F401 |
| 32 | + except (ImportError, AttributeError) as exc: |
| 33 | + raise ImportError( |
| 34 | + f"agentex-sdk could not import the agentex-client REST surface " |
| 35 | + f"(agentex-sdk={sdk or '?'}, agentex-client={client or '?'}) — reinstall " |
| 36 | + f"both at the same version (`pip install --force-reinstall agentex-sdk`)." |
| 37 | + ) from exc |
0 commit comments