Merge origin/main (561b053f79) into simp/forwardport: forward-port 220 main commits into the simplified tree

This commit is contained in:
Teknium
2026-09-03 03:31:03 -07:00
336 changed files with 22683 additions and 1704 deletions
+31 -1
View File
@@ -89,13 +89,43 @@ def get_hermes_home() -> Path:
return get_process_hermes_home()
# Resolved keys, keyed by the path string that was handed in. Path.resolve()
# is a filesystem call, and this function sits under every ToolRegistry
# lookup through current_scope_key(), so without this the registry pays a
# syscall per lookup. A process only ever sees a handful of home paths, so
# the dict stays tiny. Only paths that really exist are stored, see below.
_HOME_KEY_CACHE: dict[str, str] = {}
def hermes_home_key(path: str | Path | None = None) -> str:
"""Stable registry key for a Hermes home/profile dir.
``strict=False`` so profiles whose directories don't exist yet still get a key.
The resolved value is remembered per input path. A directory that does
not exist yet is resolved without touching the cache, because the answer
can change once it is created (e.g. part of the path turns out to be a symlink).
"""
candidate = Path(path) if path is not None else get_hermes_home()
return os.path.normcase(str(candidate.expanduser().resolve(strict=False)))
raw = str(candidate)
cached = _HOME_KEY_CACHE.get(raw)
if cached is not None:
return cached
expanded = candidate.expanduser()
try:
resolved = expanded.resolve(strict=True)
except OSError:
# Not on disk yet: lenient resolve, not stored, so the real answer is
# picked up once the directory appears.
return os.path.normcase(str(expanded.resolve(strict=False)))
key = os.path.normcase(str(resolved))
_HOME_KEY_CACHE[raw] = key
return key
def reset_hermes_home_key_cache() -> None:
"""Forget every remembered home key (for tests that move a home dir on disk)."""
_HOME_KEY_CACHE.clear()
def get_process_hermes_home() -> Path: