Skip to content

feat: 支持源码模式运行脚本链#64

Open
LevelDownRefine wants to merge 3 commits into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/support_source_code
Open

feat: 支持源码模式运行脚本链#64
LevelDownRefine wants to merge 3 commits into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/support_source_code

Conversation

@LevelDownRefine

@LevelDownRefine LevelDownRefine commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

变更

build_runner_command 新增源码模式支持:
非 frozen 环境下, 获得项目的根路径后运行
python OneDragon-ScriptChainer/src/script_chainer/win_exe/launcher.py --onedragon --chain ...

价值

  • 本地开发可直接在源码模式运行脚本链,无需先打包 exe
  • 显著简化联调/回归测试流程,缩短验证时间

测试

进过测试,以下两种方式均成功在launcher中运行单个及全体脚本

  • 在OneDragon-ScriptChainer下测试uv run python src\script_chainer\win_exe\launcher.py
  • 在OneDragon-ScriptChainer\src下测试uv run python script_chainer\win_exe\launcher.py

Summary by CodeRabbit

Bug Fixes

  • 修复源码模式下的启动异常:现在会生成可直接运行的启动命令,无需先编译或打包即可在源代码环境中正常启动。
  • 改进工作目录识别:源码模式会自动定位到项目仓库根目录,帮助确保运行环境配置一致、加载资源更可靠。

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

代码变更概述

build_runner_command 函数的源码模式(非 sys.frozen)分支由原先抛出 RuntimeError 改为构造 sys.executable 直接启动 launcher 脚本的命令,通过 Path(__file__).resolve().parents[3] 计算仓库根目录作为工作目录返回,并同步移除文档注释中的 Raises 说明。

变更详情

源码模式 runner 命令实现

Layer / File(s) Summary
源码模式命令构建与文档更新
src/script_chainer/utils/runner_utils.py
新增 Path 导入;移除文档注释中关于源码模式抛出 RuntimeErrorRaises 描述;将源码模式分支替换为通过 Path(__file__).resolve().parents[3] 计算仓库根目录,构造 sys.executable + launcher 文件路径的命令,追加 --onedragon --chain 参数和条件性的 --debug-index 参数,并返回仓库根目录作为工作目录。

估算的代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

小诗

🐇 源码模式原先只报错,
如今握起 launcher 之手~
Path 回溯找到根目录,
sys.executable 唱起欢歌,
小兔竖起大拇指:功能真灵活!🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR标题清晰准确地反映了主要改动:在源码模式下支持运行脚本链,标题简洁明了且与变更内容高度相关。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LevelDownRefine LevelDownRefine changed the title feat(runner): 支持源码模式运行脚本链 feat: 支持源码模式运行脚本链 Jun 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/script_chainer/utils/runner_utils.py (1)

41-41: 💤 Low value

建议添加路径深度检查以增强健壮性。

当前实现假设文件始终位于仓库根目录下三级深度,如果文件位置发生变化或在异常环境下运行,.parents[3] 可能引发 IndexError

🛡️ 建议的防御性检查
-        repo_root = str(Path(__file__).resolve().parents[3])
+        file_path = Path(__file__).resolve()
+        if len(file_path.parents) < 4:
+            raise RuntimeError(f"无法确定仓库根目录:文件路径 {file_path} 层级不足")
+        repo_root = str(file_path.parents[3])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/script_chainer/utils/runner_utils.py` at line 41, The current
implementation directly accesses `.parents[3]` on the resolved path without
validating that enough parent directories exist, which can raise an IndexError
if the file is not at the expected depth or runs in certain environments. Add a
defensive check before accessing `.parents[3]` to verify that the parents tuple
has at least 4 elements (indices 0-3 are valid), and either handle the
insufficient depth case gracefully (such as using a fallback value or raising a
more informative error) or validate the file location at runtime to ensure it
meets the expected directory structure requirements.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/script_chainer/utils/runner_utils.py`:
- Around line 28-42: The module execution using python -m requires a complete
package hierarchy, but the src/__init__.py file is missing, which prevents src
from being recognized as a valid Python package. Create an empty __init__.py
file in the src/ directory to establish the proper package structure required
for the -m flag to work correctly with the command being constructed in the else
block that references sys.executable and the src.script_chainer.win_exe.launcher
module path.

---

Nitpick comments:
In `@src/script_chainer/utils/runner_utils.py`:
- Line 41: The current implementation directly accesses `.parents[3]` on the
resolved path without validating that enough parent directories exist, which can
raise an IndexError if the file is not at the expected depth or runs in certain
environments. Add a defensive check before accessing `.parents[3]` to verify
that the parents tuple has at least 4 elements (indices 0-3 are valid), and
either handle the insufficient depth case gracefully (such as using a fallback
value or raising a more informative error) or validate the file location at
runtime to ensure it meets the expected directory structure requirements.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c7896ae-b989-452f-9d2f-d9320c77a9c3

📥 Commits

Reviewing files that changed from the base of the PR and between b7b55f9 and 36cbf80.

📒 Files selected for processing (1)
  • src/script_chainer/utils/runner_utils.py

Comment thread src/script_chainer/utils/runner_utils.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant