Files
hermes-agent/utils/__init__.py
alt-glitch fc9bfa05f4 fix(code-health): HX018 stops allowing pm, and utils/AGENTS.md matches the code
pm imports hermes_cli.config inside functions, so a utils helper could
reach config through it with no waiver. No utils module imports pm, so the
allowlist entry goes.

utils/AGENTS.md: the product test names its one standing exception (the
atomic writers call hermes_constants.mkdir_under_hermes_home so a write
never resurrects a deleted profile), the owner table gives
hermes_cli/config_backend.py its real path, and the submodule-import rule
is scoped to new callers. The utils/__init__.py docstring says the same.
tests/AGENTS.md no longer lists utils among the modules whose tests sit
directly in tests/.

The rule's tests now cover a root-level product module, `not in
sys.modules`, and a relative import inside utils.
2026-11-30 18:07:16 +05:30

105 lines
2.7 KiB
Python

"""Small helpers that several top-level packages share and that know nothing about Hermes as a product.
- ``utils.files``: files on disk: atomic writes and replaces, temp files, directory sync,
cleanup, file mode and owner, file signatures for caches, JSON and YAML file helpers.
- ``utils.urls``: base URL hostname, path and origin, and domain matching.
- ``utils.env``: truthy strings, numeric env vars, and proxy env var normalization.
Existing callers import from ``utils``; new code imports from the submodule. Tests patch a name in
the module that defines it.
"""
from utils.env import (
env_float,
env_int,
env_var_enabled,
is_truthy_value,
normalize_proxy_env_vars,
normalize_proxy_url,
sanitize_no_proxy_entries,
TRUTHY_STRINGS,
)
from utils.files import (
atomic_json_write,
atomic_replace,
atomic_roundtrip_yaml_save,
atomic_roundtrip_yaml_update,
atomic_write_bytes,
atomic_write_text,
atomic_yaml_write,
content_digest,
default_new_file_mode,
fast_safe_load,
file_cache_version,
file_signature,
fsync_directory,
load_yaml_file_readonly,
logger,
mkstemp_beside,
mtime_is_racy,
preserve_file_mode,
preserve_file_owner,
publish_new_file,
racy_content_digest,
RACY_MTIME_WINDOW_NS,
read_json_or_empty,
restore_file_mode,
restore_file_owner,
rmtree_readonly,
safe_json_loads,
unlink_files_older_than,
warn_if_credential_file_broadly_readable,
)
from utils.urls import (
base_url_host_matches,
base_url_hostname,
base_url_origin,
base_url_path,
same_base_url_origin,
)
__all__ = [
"RACY_MTIME_WINDOW_NS",
"TRUTHY_STRINGS",
"atomic_json_write",
"atomic_replace",
"atomic_roundtrip_yaml_save",
"atomic_roundtrip_yaml_update",
"atomic_write_bytes",
"atomic_write_text",
"atomic_yaml_write",
"base_url_host_matches",
"base_url_hostname",
"base_url_origin",
"base_url_path",
"content_digest",
"default_new_file_mode",
"env_float",
"env_int",
"env_var_enabled",
"fast_safe_load",
"file_cache_version",
"file_signature",
"fsync_directory",
"is_truthy_value",
"load_yaml_file_readonly",
"logger",
"mkstemp_beside",
"mtime_is_racy",
"normalize_proxy_env_vars",
"normalize_proxy_url",
"preserve_file_mode",
"preserve_file_owner",
"publish_new_file",
"racy_content_digest",
"read_json_or_empty",
"restore_file_mode",
"restore_file_owner",
"rmtree_readonly",
"safe_json_loads",
"same_base_url_origin",
"sanitize_no_proxy_entries",
"unlink_files_older_than",
"warn_if_credential_file_broadly_readable",
]