#!/usr/bin/env python3 """ 本仓库进程级单例:仓库根目录、对 ``config.ini`` 的一次性解析快照,以及由快照派生的常用路径与 URL。 其它脚本可在仓库根已加入 ``sys.path`` 后 ``from workplace.singleton import …``, 或通过 ``workplace.main`` 再导出的别名引用。本模块在首次导入时若根目录不在 ``sys.path`` 会自行插入。 """ from __future__ import annotations import sys from pathlib import Path # 由本文件位置解析仓库根:workplace/singleton.py → 上级上级为项目根 _SINGLETON_MODULE_SOURCE_FILE_PATH = Path(__file__).resolve() REPOSITORY_ROOT_DIRECTORY: Path = _SINGLETON_MODULE_SOURCE_FILE_PATH.parent.parent # 保证可 ``import workplace.*``(例如直接跑 ``workplace/main.py`` 时首项 path 常为 workplace 目录) _repository_root_directory_string = str(REPOSITORY_ROOT_DIRECTORY) if _repository_root_directory_string not in sys.path: sys.path.insert(0, _repository_root_directory_string) from workplace.repository_config_snapshot import ( # noqa: E402 PyAutoGUIScreenCalibration, RepositoryConfigIniSnapshot, get_repository_config_ini_snapshot, ) # ``config.ini`` 与 ``save/project-config`` 只解析一次,全进程共用(见 ``repository_config_snapshot``) REPOSITORY_CONFIG_INI_SNAPSHOT: RepositoryConfigIniSnapshot = ( get_repository_config_ini_snapshot() ) # 以下为快照字段及根目录拼接结果,便于零散导入而不必再读配置 HOME_PAGE_URL: str = REPOSITORY_CONFIG_INI_SNAPSHOT.home_page_url PYTHON_EXECUTABLE_RELATIVE_PATH: str = ( REPOSITORY_CONFIG_INI_SNAPSHOT.python_executable_relative_path ) PYTHON_EXECUTABLE_ABSOLUTE_PATH: Path = ( REPOSITORY_ROOT_DIRECTORY / PYTHON_EXECUTABLE_RELATIVE_PATH ) PYAUTOGUI_SCREEN_CALIBRATION: PyAutoGUIScreenCalibration = ( REPOSITORY_CONFIG_INI_SNAPSHOT.pyautogui_screen_calibration ) __all__ = [ "REPOSITORY_ROOT_DIRECTORY", "REPOSITORY_CONFIG_INI_SNAPSHOT", "RepositoryConfigIniSnapshot", "PyAutoGUIScreenCalibration", "HOME_PAGE_URL", "PYTHON_EXECUTABLE_RELATIVE_PATH", "PYTHON_EXECUTABLE_ABSOLUTE_PATH", "PYAUTOGUI_SCREEN_CALIBRATION", ]