Add helpful ImportError messages for optional dependencies

When optional dependencies are missing, raise ImportError with
installation
instructions pointing to the relevant extras group (e.g. `[messaging]`,
`[cli]`, `[mcp]`, etc.) instead of letting the import fail silently.
This commit is contained in:
alt-glitch 2026-04-23 04:46:01 +05:30
parent 79a5f03f92
commit 2df306e6cd
9 changed files with 81 additions and 14 deletions

View file

@ -335,10 +335,17 @@ class ProcessRegistry:
)
if use_pty:
if _IS_WINDOWS:
from winpty import PtyProcess as _PtyProcessCls
else:
from ptyprocess import PtyProcess as _PtyProcessCls
try:
if _IS_WINDOWS:
from winpty import PtyProcess as _PtyProcessCls
else:
from ptyprocess import PtyProcess as _PtyProcessCls
except ImportError:
pkg = "winpty" if _IS_WINDOWS else "ptyprocess"
raise ImportError(
f"{pkg} is required for PTY mode. "
"Install with: pip install hermes-agent[pty]"
) from None
try:
user_shell = _find_shell()
pty_env = _sanitize_subprocess_env(os.environ, env_vars)