Files
sanguo_moziplus_v2/src/utils.py
T
cfdaily 09a0928bbc
CI / lint (push) Successful in 8s
CI / lint (pull_request) Successful in 5s
CI / test (push) Failing after 8s
CI / test (pull_request) Failing after 8s
CI / notify-on-failure (push) Successful in 1s
CI / notify-on-failure (pull_request) Successful in 3s
fix: resolve all flake8 lint errors (118 → 0)
2026-06-09 16:43:41 +08:00

37 lines
960 B
Python

"""路径解析工具 — 统一获取项目数据根目录
优先级:
1. BLACKBOARD_ROOT 环境变量
2. config/default.yaml 的 data_root
3. 相对于源码目录的 data/
"""
from __future__ import annotations
import os
from pathlib import Path
def get_data_root() -> Path:
"""获取项目数据根目录"""
# 1. 环境变量最高优先级
root = os.environ.get("BLACKBOARD_ROOT")
if root:
return Path(root)
# 2. 从 config/default.yaml 读取
try:
import yaml
config_path = Path(__file__).parent.parent / "config" / "default.yaml"
if config_path.exists():
with open(config_path) as f:
cfg = yaml.safe_load(f) or {}
data_root = cfg.get("data_root")
if data_root:
return Path(data_root).expanduser()
except Exception:
pass
# 3. 相对于源码目录的 data/
return Path(__file__).parent.parent / "data"