calc-framework/scripts/_path_setup.py

43 lines
1.3 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.

# SPDX-License-Identifier: AGPL-3.0
"""为 scripts/ 目录下的入口脚本提供项目根路径设置。
用法::
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _path_setup import ensure_root
ensure_root()
"""
import sys
from pathlib import Path
def ensure_root() -> None:
"""将项目根目录scripts/ 的父目录)加入 sys.path。"""
root = Path(__file__).resolve().parent.parent
if str(root) not in sys.path:
sys.path.insert(0, str(root))
def ensure_tools() -> None:
"""将 tools/ 加入 sys.pathendfield_designer 等包)。"""
tools = Path(__file__).resolve().parent.parent / "tools"
if str(tools) not in sys.path:
sys.path.insert(0, str(tools))
def ensure_framework_src() -> None:
"""将 framework/src 加入 sys.pathcalc_framework 源码开发模式)。"""
src = Path(__file__).resolve().parent.parent / "framework" / "src"
if str(src) not in sys.path:
sys.path.insert(0, str(src))
def ensure_games_endfield() -> None:
"""将 games/endfield 加入 sys.pathgui 等顶层包)。"""
pkg = Path(__file__).resolve().parent.parent / "games" / "endfield"
if str(pkg) not in sys.path:
sys.path.insert(0, str(pkg))