scripts/_hermes_home.py
scripts/_hermes_home.pyBrowse 7 files
384 tokens
1,636 bytes
Token encoding: o200k_base
Snapshot 24fd22b
← Back to SKILL.md
1"""Resolve HERMES_HOME for standalone skill scripts.2 3Skill scripts may run outside the Hermes process (e.g. system Python,4nix env, CI) where ``hermes_constants`` is not importable. This module5provides the same ``get_hermes_home()`` and ``display_hermes_home()``6contracts as ``hermes_constants`` without requiring it on ``sys.path``.7 8When ``hermes_constants`` IS available it is used directly so that any9future enhancements (profile resolution, Docker detection, etc.) are10picked up automatically. The fallback path replicates the core logic11from ``hermes_constants.py`` using only the stdlib.12 13All scripts under ``google-workspace/scripts/`` should import from here14instead of duplicating the ``HERMES_HOME = Path(os.getenv(...))`` pattern.15"""16 17from __future__ import annotations18 19import os20from pathlib import Path21 22try:23 from hermes_constants import display_hermes_home as display_hermes_home24 from hermes_constants import get_hermes_home as get_hermes_home25except (ModuleNotFoundError, ImportError):26 27 def get_hermes_home() -> Path:28 """Return the Hermes home directory (default: ~/.hermes).29 30 Mirrors ``hermes_constants.get_hermes_home()``."""31 val = os.environ.get("HERMES_HOME", "").strip()32 return Path(val) if val else Path.home() / ".hermes"33 34 def display_hermes_home() -> str:35 """Return a user-friendly ``~/``-shortened display string.36 37 Mirrors ``hermes_constants.display_hermes_home()``."""38 home = get_hermes_home()39 try:40 return "~/" + home.relative_to(Path.home()).as_posix()41 except ValueError:42 return str(home)43