diff --git a/bin/run_cli.py b/bin/run_cli.py index f21b991..9e6c29c 100644 --- a/bin/run_cli.py +++ b/bin/run_cli.py @@ -5,6 +5,11 @@ import os import shutil import sys +# ==== 将项目根目录加入 sys.path,确保后续所有 douyin.* 导入正常 ================ +_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if _BASE_DIR not in sys.path: + sys.path.insert(0, _BASE_DIR) + # 可选:全局参数/调用跟踪(仅在环境变量 PARAM_TRACK_ALL=1 时启用) if os.environ.get("PARAM_TRACK_ALL") == "1": try: @@ -47,10 +52,6 @@ except Exception as e: # 如果需要从外部工作树加载兼容模块,可显式设置 EXTERNAL_DOUYIN_FUDAI_DIR。 # 默认只使用当前仓库内置实现,避免绑定到某台机器的 Cursor worktree 路径。 -_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -# 确保项目根在 sys.path 中(脚本从 bin/ 目录启动时) -if _BASE_DIR not in sys.path: - sys.path.insert(0, _BASE_DIR) _EXTERNAL_DOUYIN_FUDAI_DIR = os.environ.get("EXTERNAL_DOUYIN_FUDAI_DIR", "").strip() diff --git a/tools/adb/auto_connect_wifi_adb.py b/tools/adb/auto_connect_wifi_adb.py index 5241fdb..0db87a2 100644 --- a/tools/adb/auto_connect_wifi_adb.py +++ b/tools/adb/auto_connect_wifi_adb.py @@ -16,7 +16,7 @@ from typing import List # 当从 tools 目录直接运行脚本时,Python 的 sys.path[0] 会是 tools/,需要把项目根目录加入路径 this_dir = os.path.dirname(os.path.abspath(__file__)) -project_root = os.path.abspath(os.path.join(this_dir, "..")) +project_root = os.path.abspath(os.path.join(this_dir, "..", "..")) if project_root not in sys.path: sys.path.insert(0, project_root) diff --git a/tools/dev/dump_room_map_test.py b/tools/dev/dump_room_map_test.py index a76aba2..57b26fc 100644 --- a/tools/dev/dump_room_map_test.py +++ b/tools/dev/dump_room_map_test.py @@ -1,3 +1,10 @@ +import os +import sys + +_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _PROJECT_ROOT not in sys.path: + sys.path.insert(0, _PROJECT_ROOT) + from douyin.reservation import douyin_reservation_handler as rh diff --git a/tools/dev/simulate_swipe_trigger.py b/tools/dev/simulate_swipe_trigger.py index eac7efb..1a8c157 100644 --- a/tools/dev/simulate_swipe_trigger.py +++ b/tools/dev/simulate_swipe_trigger.py @@ -1,3 +1,10 @@ +import os +import sys + +_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _PROJECT_ROOT not in sys.path: + sys.path.insert(0, _PROJECT_ROOT) + from douyin.core.douyin_fudai import fudai_analyse from douyin.handlers import douyin_swipe_ops diff --git a/tools/diagnostics/check_gui_params_conflicts.py b/tools/diagnostics/check_gui_params_conflicts.py index ee74492..ce0b558 100644 --- a/tools/diagnostics/check_gui_params_conflicts.py +++ b/tools/diagnostics/check_gui_params_conflicts.py @@ -15,14 +15,13 @@ if sys.platform == "win32": except Exception: pass -try: - from douyin.core import path_config +_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _PROJECT_ROOT not in sys.path: + sys.path.insert(0, _PROJECT_ROOT) - CONFIG_PATH = path_config.get_config_path() -except Exception: - from douyin.core import path_config +from douyin.core import path_config - CONFIG_PATH = path_config.get_config_path() +CONFIG_PATH = path_config.get_config_path() def check_conflicts(cfg: dict) -> list: diff --git a/tools/diagnostics/diagnose_runtime_flags.py b/tools/diagnostics/diagnose_runtime_flags.py index 7fe1743..da4d5bc 100644 --- a/tools/diagnostics/diagnose_runtime_flags.py +++ b/tools/diagnostics/diagnose_runtime_flags.py @@ -1,3 +1,10 @@ +import os +import sys + +_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _PROJECT_ROOT not in sys.path: + sys.path.insert(0, _PROJECT_ROOT) + from douyin.core.douyin_fudai import fudai_analyse from douyin.utils import douyin_config diff --git a/tools/diagnostics/run_screenshot_diagnostics.py b/tools/diagnostics/run_screenshot_diagnostics.py index f45000d..727bf65 100644 --- a/tools/diagnostics/run_screenshot_diagnostics.py +++ b/tools/diagnostics/run_screenshot_diagnostics.py @@ -1,6 +1,13 @@ -from douyin.core.underlying_operations import underlying_operations +import os +import sys import time +_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _PROJECT_ROOT not in sys.path: + sys.path.insert(0, _PROJECT_ROOT) + +from douyin.core.underlying_operations import underlying_operations + op = underlying_operations() # try to trigger several screenshots for i in range(8):