Files
sanguo_moziplus_v2/src/utils.py
T
cfdaily d58e38d58f
CI / lint (pull_request) Successful in 6s
CI / test (pull_request) Successful in 9s
CI / notify-on-failure (pull_request) Successful in 0s
fix(lint): 修复 PR #14 引入的 lint 回退 (119→0)
PR #14 从旧分支复制文件导致回退了 PR #10 的 lint 修复。
修复内容:
- autoflake 移除未使用导入/变量
- autopep8 修复缩进/空格
- 手动修复 F821(pathlib→Path), F541(f-string), F841(未使用变量)
- 所有修复均通过 flake8 --max-line-length=120 --extend-ignore=E501 检查 (0 errors)
2026-06-09 23:53:29 +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"