31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
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 # 方便调试/日志 |