fix: explicit UTF-8 encoding on all read_text() calls — v0.50.89 (PR #700 by @woaijiadanoo)
Fixes config loading failures on Windows with non-UTF-8 default locales (GBK, Shift_JIS etc). All Path.read_text() calls in api/config.py and api/profiles.py now specify encoding='utf-8'.
This commit is contained in:
@@ -198,7 +198,7 @@ def reload_config() -> None:
|
|||||||
import yaml as _yaml
|
import yaml as _yaml
|
||||||
|
|
||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
loaded = _yaml.safe_load(config_path.read_text())
|
loaded = _yaml.safe_load(config_path.read_text(encoding="utf-8"))
|
||||||
if isinstance(loaded, dict):
|
if isinstance(loaded, dict):
|
||||||
_cfg_cache.update(loaded)
|
_cfg_cache.update(loaded)
|
||||||
try:
|
try:
|
||||||
@@ -770,7 +770,7 @@ def get_available_models() -> dict:
|
|||||||
try:
|
try:
|
||||||
import json as _j
|
import json as _j
|
||||||
|
|
||||||
auth_store = _j.loads(auth_store_path.read_text())
|
auth_store = _j.loads(auth_store_path.read_text(encoding="utf-8"))
|
||||||
active_provider = auth_store.get("active_provider")
|
active_provider = auth_store.get("active_provider")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Failed to load auth store from %s", auth_store_path)
|
logger.debug("Failed to load auth store from %s", auth_store_path)
|
||||||
@@ -818,7 +818,7 @@ def get_available_models() -> dict:
|
|||||||
env_keys = {}
|
env_keys = {}
|
||||||
if hermes_env_path.exists():
|
if hermes_env_path.exists():
|
||||||
try:
|
try:
|
||||||
for line in hermes_env_path.read_text().splitlines():
|
for line in hermes_env_path.read_text(encoding="utf-8").splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and not line.startswith("#") and "=" in line:
|
if line and not line.startswith("#") and "=" in line:
|
||||||
k, v = line.split("=", 1)
|
k, v = line.split("=", 1)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ def _read_active_profile_file() -> str:
|
|||||||
ap_file = _DEFAULT_HERMES_HOME / 'active_profile'
|
ap_file = _DEFAULT_HERMES_HOME / 'active_profile'
|
||||||
if ap_file.exists():
|
if ap_file.exists():
|
||||||
try:
|
try:
|
||||||
name = ap_file.read_text().strip()
|
name = ap_file.read_text(encoding="utf-8").strip()
|
||||||
if name:
|
if name:
|
||||||
return name
|
return name
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -142,7 +142,7 @@ def _reload_dotenv(home: Path):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
loaded_keys: set[str] = set()
|
loaded_keys: set[str] = set()
|
||||||
for line in env_path.read_text().splitlines():
|
for line in env_path.read_text(encoding="utf-8").splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and not line.startswith('#') and '=' in line:
|
if line and not line.startswith('#') and '=' in line:
|
||||||
k, v = line.split('=', 1)
|
k, v = line.split('=', 1)
|
||||||
@@ -344,7 +344,7 @@ def _write_endpoint_to_config(profile_dir: Path, base_url: str = None, api_key:
|
|||||||
cfg = {}
|
cfg = {}
|
||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
try:
|
try:
|
||||||
loaded = _yaml.safe_load(config_path.read_text())
|
loaded = _yaml.safe_load(config_path.read_text(encoding="utf-8"))
|
||||||
if isinstance(loaded, dict):
|
if isinstance(loaded, dict):
|
||||||
cfg = loaded
|
cfg = loaded
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user