mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-11 03:31:55 +00:00
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:
parent
847ffca715
commit
850973295e
9 changed files with 81 additions and 14 deletions
|
|
@ -1501,7 +1501,13 @@ def _snapshot_child_pids() -> set:
|
|||
pass
|
||||
|
||||
# Fallback: psutil
|
||||
import psutil
|
||||
try:
|
||||
import psutil
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"psutil is required for MCP child process tracking. "
|
||||
"Install with: pip install hermes-agent[mcp]"
|
||||
) from None
|
||||
try:
|
||||
return {c.pid for c in psutil.Process(my_pid).children()}
|
||||
except psutil.Error:
|
||||
|
|
|
|||
|
|
@ -71,7 +71,13 @@ def main():
|
|||
|
||||
ref_text = ref_text_path.read_text(encoding="utf-8").strip()
|
||||
|
||||
from neutts import NeuTTS
|
||||
try:
|
||||
from neutts import NeuTTS
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"neutts is required for local TTS synthesis. "
|
||||
"Install with: pip install hermes-agent[tts-local]"
|
||||
) from None
|
||||
|
||||
tts = NeuTTS(
|
||||
backbone_repo=args.model,
|
||||
|
|
@ -86,7 +92,13 @@ def main():
|
|||
out_path = Path(args.out)
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
import soundfile as sf
|
||||
try:
|
||||
import soundfile as sf
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"soundfile is required for audio output. "
|
||||
"Install with: pip install hermes-agent[tts-local]"
|
||||
) from None
|
||||
sf.write(str(out_path), wav, 24000)
|
||||
|
||||
print(f"OK: {out_path}", file=sys.stderr)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -318,7 +318,13 @@ def _resize_image_for_vision(image_path: Path, mime_type: Optional[str] = None,
|
|||
else:
|
||||
data_url = None # defer full encode; try Pillow resize first
|
||||
|
||||
from PIL import Image
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Pillow is required for image resizing. "
|
||||
"Install with: pip install hermes-agent[cli]"
|
||||
) from None
|
||||
import io as _io
|
||||
|
||||
logger.info("Image file is %.1f MB (estimated base64 %.1f MB, limit %.1f MB), auto-resizing...",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue