diff --git a/src/script_chainer/utils/runner_utils.py b/src/script_chainer/utils/runner_utils.py index c467b76..1f05f19 100644 --- a/src/script_chainer/utils/runner_utils.py +++ b/src/script_chainer/utils/runner_utils.py @@ -2,8 +2,13 @@ import os import sys +from one_dragon.utils.os_utils import get_work_dir, get_path_under_work_dir +def get_launcher_path() -> str: + """获取 launcher 路径。""" + return get_path_under_work_dir("src", "script_chainer", "win_exe", "launcher.py") + def build_runner_command(chain_name: str, script_index: int | None = None) -> tuple[list[str], str | None]: """构造 runner 启动命令。 @@ -13,19 +18,21 @@ def build_runner_command(chain_name: str, script_index: int | None = None) -> tu Returns: 启动命令及其工作目录。 - - Raises: - RuntimeError: 源码模式下不支持运行脚本链。 """ + common_args = ["--onedragon", "--chain", chain_name] + if script_index is not None: + common_args.extend(["--debug-index", str(script_index)]) + + # 可执行文件模式 if getattr(sys, 'frozen', False): + command = [sys.executable, *common_args] + return command, os.path.dirname(sys.executable) or None + else: # 源码模式 + repo_root = get_work_dir() + launcher_path = get_launcher_path() command = [ sys.executable, - '--onedragon', - '--chain', - chain_name, + launcher_path, + *common_args, ] - if script_index is not None: - command.extend(['--debug-index', str(script_index)]) - return command, os.path.dirname(sys.executable) or None - - raise RuntimeError('源码模式下不支持运行脚本链,请使用打包后的程序。') + return command, repo_root