Skip to content

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

Merged
ShadowLemoon merged 6 commits into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/support_source_code
Jun 20, 2026
Merged

feat: 支持源码模式运行脚本链#64
ShadowLemoon merged 6 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 环境下, 选择src作为子进程的workdir,并使用模块方式启动
python -m script_chainer.win_exe.launcher.py --onedragon --chain ...

价值

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

测试

cd OneDragon-ScriptChainer/src
uv run python -m script_chainer.win_exe.launcher

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • 修复源码模式下启动异常:现在会自动生成可直接运行的启动命令与工作目录,无需先编译或打包。
    • 优化源码模式启动方式:改为使用统一的启动器入口,并确保链式任务参数(含调试索引)按公共参数规则追加传递。
    • 改进工作目录识别:冻结/打包与源码模式下的工作目录与执行方式更一致,提升资源加载稳定性。

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

核心变更

修改 build_runner_command() 函数实现:新增 get_path_under_work_dir 导入,统一公共参数由 common_args 生成,源码模式从抛出 RuntimeError 改为通过 launcher 模块执行,工作目录改用 get_path_under_work_dir("src")

变更详情

源码模式 runner 命令实现

Layer / File(s) Summary
runner 命令构建完整实现
src/script_chainer/utils/runner_utils.py
新增 get_path_under_work_dir 导入,重写 build_runner_command() 函数:统一构造 common_args(包含 --onedragon --chain <chain_name>,当 script_index 非空时追加 --debug-index);冻结模式保留 sys.executable 执行方式并返回 os.path.dirname(sys.executable) or None 作为工作目录;源码模式改为通过 sys.executable -m script_chainer.win_exe.launcher 启动,返回 get_path_under_work_dir("src") 作为工作目录,替换原有的 RuntimeError

估算的代码审查工作量

🎯 3 (Moderate) | ⏱️ ~20 分钟

可能相关的 PR

  • OneDragon-Anything/OneDragon-ScriptChainer#46:进一步修改 build_runner_command() 实现,包括 --debug-index 和执行/工作目录行为,这是 PR #46 的 GUI 运行优化中引入的 runner 命令辅助函数。

小诗

🐇 源码模式曾只报错声,
而今 launcher 启程迎风!
get_path_under_work_dir 定位真,
common_args 统一新韵律,
小兔欢呼:双模式齐备!🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确地反映了本次变更的核心内容,即添加源码模式(而非冻结模式)的脚本链执行支持。
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

@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

🤖 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 10-11: The call to get_path_under_work_dir on line 11 incorrectly
passes repo_root (an absolute path) as the first argument, but according to the
pattern of all other call sites in the repository, this function expects only
relative path segments. The function internally calls get_work_dir() for path
construction, so remove the repo_root parameter and pass only the relative path
components ("src", "script_chainer", "win_exe", "launcher.py") to
get_path_under_work_dir. This will fix the launcher path construction failure in
source code mode that causes build_runner_command to fail.
🪄 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: 505449ea-a990-43b8-b87c-256b079fbc8b

📥 Commits

Reviewing files that changed from the base of the PR and between cd3ac74 and c5269fa.

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

Comment thread src/script_chainer/utils/runner_utils.py Outdated
@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

@ShadowLemoon Could you help check this pr?

@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

@ShadowLemoon

Copy link
Copy Markdown
Collaborator

源码的话运行目录可能不是项目根目录吧,既然写死目录了可以从本文件路径出发往上走

@LevelDownRefine

This comment was marked as outdated.

@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

源码的话运行目录可能不是项目根目录吧,既然写死目录了可以从本文件路径出发往上走

我改了改,子进程的cwd指定为OneDragon-ScriptChainer/src,cmd中使用模块方式启动
这样应该会更稳定一些

@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

Could you help review again? @ShadowLemoon

@ShadowLemoon ShadowLemoon merged commit bd20da7 into OneDragon-Anything:main Jun 20, 2026
3 checks passed
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.

2 participants