paths.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """Where the store, lockfile, and installed-state file live."""
  2. from __future__ import annotations
  3. import os
  4. from pathlib import Path
  5. def repo_root() -> Path:
  6. return Path(__file__).resolve().parent.parent
  7. def install_root() -> Path:
  8. """The tree this process runs from. ``HERMES_INSTALL_ROOT`` when a steward
  9. wrapper sets it (Nix points it at the sealed tree whose install stamp lives
  10. outside the package dir), else the executing checkout."""
  11. env = os.environ.get("HERMES_INSTALL_ROOT")
  12. return Path(env) if env else repo_root()
  13. def install_stamp_path(project_root: Path) -> Path:
  14. """THE stamp location for ``project_root``, shared by every stamp reader.
  15. Beside the code in checkouts, Docker and desktop payloads. A Nix package
  16. bakes the stamp outside the store's package dir and its wrapper carries
  17. ``HERMES_INSTALL_ROOT`` for the executing tree only — so the executing
  18. tree resolves through install_root, any other tree is taken literally.
  19. PM reads it in sealed stages (the Docker runtime base) before hermes_cli
  20. ships, so it lives here rather than beside the stewards.
  21. """
  22. root = Path(project_root)
  23. if root.resolve() == repo_root():
  24. root = install_root()
  25. return root / "install-stamp.json"
  26. def lockfile_path() -> Path:
  27. return Path(__file__).resolve().parent / "lock.json"
  28. def store_root() -> Path:
  29. from pm.environments import store_root as resolve
  30. return resolve(repo_root())
  31. def partials_root() -> Path:
  32. """The downloader's managed partials area: machine-scoped and shared
  33. (keyed by sha256(url), so two callers or two profiles reuse one
  34. partial), but anchored to the DEFAULT hermes root — NOT the byte
  35. store. The store can live inside a read-only sealed payload
  36. (WindowsApps/agent-payload), and partials are mutable state the
  37. downloader writes continuously, so they must land somewhere writable
  38. on every install kind: ``%LOCALAPPDATA%\\hermes\\cache\\partials`` on
  39. Windows, ``~/.hermes/cache/partials`` on POSIX.
  40. """
  41. from hermes_constants import get_default_hermes_root
  42. return get_default_hermes_root() / "cache" / "partials"
  43. def facts_path() -> Path:
  44. return store_root() / "facts.json"
  45. def writable_store_root() -> Path:
  46. if not (store_root().parent / "manifest.json").is_file():
  47. return store_root()
  48. from hermes_constants import get_default_hermes_root
  49. return get_default_hermes_root() / "tools"
  50. def runtime_facts_path() -> Path:
  51. from pm.environments import runtime_facts_path as resolve
  52. return resolve(repo_root())