"""从 JSON 或 config.txt 风格文件读取部署参数。""" from __future__ import annotations import json from pathlib import Path from typing import Any def load_params_file(path: str | Path) -> dict[str, Any]: """自动识别 JSON/config.txt 格式,并返回参数字典。""" config_path = Path(path) text = config_path.read_text(encoding="utf-8") stripped = text.lstrip() if stripped.startswith("{"): return json.loads(text) values: dict[str, Any] = {} for raw_line in text.splitlines(): line = raw_line.strip() if not line or line.startswith("#"): continue if "=" not in line: continue key, value = line.split("=", 1) values[key.strip()] = value.strip() return values