修正引用路径;恢复project_info.py到service目录,新增config/project_info.yml配置文件
This commit is contained in:
22
app/services/project_info.py
Normal file
22
app/services/project_info.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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']
|
||||
Reference in New Issue
Block a user