feat: 支持源码模式运行脚本链#64
Conversation
代码变更概述
变更详情源码模式 runner 命令实现
估算的代码审查工作量🎯 2 (Simple) | ⏱️ ~10 分钟 小诗
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/script_chainer/utils/runner_utils.py
变更
build_runner_command新增源码模式支持:非 frozen 环境下, 获得项目的根路径后运行
python OneDragon-ScriptChainer/src/script_chainer/win_exe/launcher.py --onedragon --chain ...价值
测试
进过测试,以下两种方式均成功在launcher中运行单个及全体脚本
uv run python src\script_chainer\win_exe\launcher.pyuv run python script_chainer\win_exe\launcher.pySummary by CodeRabbit
Bug Fixes