23 lines
796 B
Python
23 lines
796 B
Python
import os
|
|
import yaml
|
|
|
|
# 获取当前项目根目录的路径
|
|
_current_file = os.path.abspath(__file__)
|
|
project_root = os.path.dirname(os.path.dirname(os.path.dirname(_current_file)))
|
|
|
|
# 尝试读取 .yml 或 .yaml 文件
|
|
config_file = os.path.join(project_root, "configs", "project_info.yml")
|
|
if not os.path.exists(config_file):
|
|
config_file = os.path.join(project_root, "configs", "project_info.yaml")
|
|
|
|
if not os.path.exists(config_file):
|
|
raise FileNotFoundError(f"未找到项目配置文件 (project_info.yaml 或 .yml): {os.path.dirname(config_file)}")
|
|
|
|
with open(config_file, 'r', encoding='utf-8') as f:
|
|
_config = yaml.safe_load(f)
|
|
|
|
if not _config or 'name' not in _config:
|
|
raise KeyError(f"项目配置文件中缺少 'name' 配置: {config_file}")
|
|
|
|
name = _config['name']
|