Files
hsa/Html/bootstrap.py
2025-08-27 19:39:38 +08:00

31 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 # 方便调试/日志