mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 03:23:23 +08:00
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def _normalize_sys_path_for_repo_layout() -> None:
|
|
"""
|
|
Allow running pytest from the ``oclaw`` subdirectory.
|
|
|
|
When cwd is ``.../chatgpt/oclaw``, Python may resolve ``import platform``
|
|
to ``oclaw/platform`` instead of stdlib ``platform``. We force sys.path to
|
|
prefer repository root (which contains the ``oclaw`` package directory).
|
|
"""
|
|
this_file = Path(__file__).resolve()
|
|
oclaw_dir = this_file.parents[1]
|
|
repo_root = oclaw_dir.parent
|
|
|
|
oclaw_dir_str = str(oclaw_dir)
|
|
repo_root_str = str(repo_root)
|
|
|
|
sys.path[:] = [p for p in sys.path if p and Path(p).resolve() != oclaw_dir]
|
|
if repo_root_str not in sys.path:
|
|
sys.path.insert(0, repo_root_str)
|
|
|
|
mod = sys.modules.get("platform")
|
|
if mod is not None:
|
|
mod_file = str(getattr(mod, "__file__", "") or "")
|
|
if "oclaw\\platform" in mod_file.replace("/", "\\"):
|
|
sys.modules.pop("platform", None)
|
|
importlib.import_module("platform")
|
|
|
|
|
|
_normalize_sys_path_for_repo_layout()
|
|
|