fix: entry-point scripts douyin.* import 失败 — sys.path 在 import 之后才设置

bin/run_cli.py 的 _BASE_DIR+sys.path.insert 原在 logging import 之后,
导致 No module named 'douyin' 警告。tools/ 下 5 个脚本完全缺失 sys.path
设置,auto_connect_wifi_adb.py 层级算错只跳到 tools/ 而非项目根。
This commit is contained in:
Codex committed 2026-05-23 18:11:18 +08:00
1 parent f750969df3
commit 2fab3f238e
7 files changed
+40 -12

No files matched your search

+5 -4
View File
@@ -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()
+1 -1
View File
@@ -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)
+7
View File
@@ -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
+7
View File
@@ -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
@@ -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:
@@ -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
@@ -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):