Skip to content

Commit cd3ac74

Browse files
refine code
1 parent 338ceb7 commit cd3ac74

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

‎src/script_chainer/utils/runner_utils.py‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,26 @@ def build_runner_command(chain_name: str, script_index: int | None = None) -> tu
1515
Returns:
1616
启动命令及其工作目录。
1717
"""
18+
common_args = ["--onedragon", "--chain", chain_name]
19+
if script_index is not None:
20+
common_args.extend(["--debug-index", str(script_index)])
21+
22+
# 可执行文件模式
1823
if getattr(sys, 'frozen', False):
19-
command = [
20-
sys.executable,
21-
'--onedragon',
22-
'--chain',
23-
chain_name,
24-
]
25-
if script_index is not None:
26-
command.extend(['--debug-index', str(script_index)])
24+
command = [sys.executable, *common_args]
2725
return command, os.path.dirname(sys.executable) or None
2826
else: # 源码模式
27+
file_path = Path(__file__).resolve()
28+
if len(file_path.parents) < 4:
29+
raise RuntimeError(f"无法确定仓库根目录: {file_path}")
30+
2931
# 根据该文件路径OneDragon-ScriptChainer\\src\\script_chainer\\utils\\runner_utils.py
3032
# 上跳三级得到仓库根目录 OneDragon-ScriptChainer
31-
repo_root = str(Path(__file__).resolve().parents[3])
32-
launcher_path = os.path.join(repo_root, "src", "script_chainer", "win_exe", "launcher.py")
33+
repo_root = str(file_path.parents[3])
34+
launcher_path = str(Path(repo_root) / "src" / "script_chainer" / "win_exe" / "launcher.py")
3335
command = [
3436
sys.executable,
3537
launcher_path,
36-
"--onedragon",
37-
"--chain",
38-
chain_name,
38+
*common_args,
3939
]
40-
if script_index is not None:
41-
command.extend(["--debug-index", str(script_index)])
42-
return command, repo_root
40+
return command, repo_root

0 commit comments

Comments
 (0)