Version 0.1.1 rise to flask app factory

This commit is contained in:
CakeCN
2025-08-27 19:39:38 +08:00
parent 8dba8688a7
commit 5c0187bc4b
55 changed files with 1708 additions and 613 deletions

31
Html/bootstrap.py Normal file
View File

@@ -0,0 +1,31 @@
from pathlib import Path
import sys, os
def bootstrap_paths():
"""
'AlgoriAgent'(位于 repo_root/AlgoriAgent可被 import
并提供 STUDENT_WORKSPACE_ROOT 的默认值repo_root/study
适配当前工厂位置repo_root/Html/apps/__init__.py
"""
here = Path(__file__).resolve()
# repo_root = .../Html/apps/../../ => parents[2]
repo_root = here.parents[2]
# 兜底:如果目录结构变化,尝试向上搜索包含 AlgoriAgent 的目录作为 repo_root
if not (repo_root / "AlgoriAgent").exists():
for p in here.parents:
if (p / "AlgoriAgent").is_dir():
repo_root = p
break
# 确保仓库根在 sys.path这样 'AlgoriAgent' 顶层包可被发现)
repo_root_str = str(repo_root)
if repo_root_str not in sys.path:
sys.path.insert(0, repo_root_str)
# 可选:如果你还有其它顶层包,也可在此处继续插入
# 默认学习工作区目录(也可放到 config.ini / 环境变量覆盖)
os.environ.setdefault("STUDENT_WORKSPACE_ROOT", str(repo_root / "study"))
return repo_root # 方便调试/日志