Files
hermes-agent/tools/connectors/__init__.py
kshitijk4poor ddc0e65958 refactor(connectors): trim lazy-surface docstrings and test path setup
Gate finding BN21 r1 quality (Lows):
- The race/eager-import snippets put the repo on sys.path three ways; PYTHONPATH and
  cwd already do it, so drop the in-snippet sys.path.insert and the REPO_ROOT templating.
- The deadlock explanation was spelled out in the module docstring, again in the
  __getattr__ docstring, and a third time in the test module. Cut it to a 2-line
  pointer to the test, and give __getattr__ a one-line docstring that describes what
  it does (cache the name in globals()).
- Unquote the dict[str, str] / list[str] annotations: requires-python is >=3.11.

No behaviour change. Both kept tests still pass on HEAD and fail with BASE
tools/connectors/__init__.py.
2026-10-03 16:56:51 +05:30

42 lines
1.7 KiB
Python

"""Connector integration boundary for managed gateway accounts and local MCP servers.
Only the names below are cross-package surface; imports beyond it need a design decision.
Siblings: ``contract`` (states, actors, transition table), ``operation`` (the record),
``live`` (open operation per session), ``run`` (the lifecycle loop), ``managed`` / ``mcp``
(per-kind hooks), ``targets``, ``search``, ``dispatch``, ``gateway/`` (HTTP wire + client).
The surface is exported lazily (PEP 562): eager submodule imports here deadlocked the
concurrent registry scan and the Group Chat worker (see test_connectors_import_deadlock.py).
"""
import importlib
# name -> module owning it: the single source of truth for __all__ and __getattr__.
_LAZY_EXPORTS: dict[str, str] = {
"CONNECTOR_BATCH_SENTINEL": "tools.connectors.gateway.names",
"MANAGE_CONNECTIONS_SCHEMA": "tools.connectors.tool",
"connector_describe": "tools.connectors.gateway.bridge",
"connector_search_hits": "tools.connectors.gateway.bridge",
"connectors_available": "tools.connectors.gateway.config",
"dispatch_connector_batch": "tools.connectors.dispatch",
"dispatch_connector_call": "tools.connectors.dispatch",
"is_connector_name": "tools.connectors.gateway.names",
"manage_connections": "tools.connectors.tool",
}
__all__ = sorted(_LAZY_EXPORTS)
def __getattr__(name: str):
"""Resolve and cache a public name on first access (PEP 562)."""
module_name = _LAZY_EXPORTS.get(name)
if module_name is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
value = getattr(importlib.import_module(module_name), name)
globals()[name] = value
return value
def __dir__() -> list[str]:
return sorted(set(globals()) | set(__all__))