From a6873ae2eedacd0bffc91185b01ab00bcfa8a6cc Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Tue, 12 May 2026 09:40:46 +0800 Subject: [PATCH] fix: resolve YAML config path relative to project root Ensure config/settings.yaml can be found when running from any working directory by resolving the path relative to the settings.py file location rather than the current working directory. Co-Authored-By: Claude Opus 4.6 (1M context) --- config/settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/settings.py b/config/settings.py index 71761ec..ae083cf 100644 --- a/config/settings.py +++ b/config/settings.py @@ -45,7 +45,12 @@ class Settings(BaseModel): def load_settings(config_path: str = "config/settings.yaml") -> Settings: """加载 YAML 配置文件""" + # Resolve relative to the project root (where config/ directory exists) path = Path(config_path) + if not path.is_absolute(): + # __file__ is config/settings.py, so parent.parent gives us project root + project_root = Path(__file__).resolve().parent.parent + path = project_root / config_path if not path.exists(): raise FileNotFoundError( f"配置文件不存在: {config_path}\n"