fix(api): use sys.executable for plugin action subprocess calls#277
Conversation
📝 WalkthroughWalkthroughRemoved a redundant local Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
web_interface/blueprints/api_v3.py (1)
5150-5150:⚠️ Potential issue | 🟠 MajorRemaining hardcoded
python3keeps the same bug for parameterized plugin actions.Line 5150 and Line 5211 still hardcode
python3, so actions with params/OAuth step 2 can fail in environments where only the current interpreter path is valid.♻️ Proposed fix
- result = subprocess.run( - ['python3', wrapper_path], + result = subprocess.run( + [sys.executable, wrapper_path], capture_output=True, text=True, timeout=120, env=env ) ... - result = subprocess.run( - ['python3', wrapper_path], + result = subprocess.run( + [sys.executable, wrapper_path], capture_output=True, text=True, timeout=120, env=env )As per coding guidelines, "Handle different deployment contexts with environment awareness in code".
Also applies to: 5211-5211
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web_interface/blueprints/api_v3.py` at line 5150, The code currently hardcodes 'python3' in the command invocation that runs wrapper_path which breaks in environments where the running interpreter is different; update the command lists that include ['python3', wrapper_path] to use the running interpreter (sys.executable) instead, add "import sys" if not present, and change both occurrences around the wrapper_path use (the two hardcoded lines noted) so they consistently use sys.executable to spawn the wrapper with the current Python binary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@web_interface/blueprints/api_v3.py`:
- Line 5150: The code currently hardcodes 'python3' in the command invocation
that runs wrapper_path which breaks in environments where the running
interpreter is different; update the command lists that include ['python3',
wrapper_path] to use the running interpreter (sys.executable) instead, add
"import sys" if not present, and change both occurrences around the wrapper_path
use (the two hardcoded lines noted) so they consistently use sys.executable to
spawn the wrapper with the current Python binary.
The execute_plugin_action endpoint hardcoded 'python3' when spawning plugin scripts via subprocess. This can fail if the system Python is named differently or if a virtualenv is active, since 'python3' may not point to the correct interpreter. Changes: - Replace 'python3' with sys.executable in the non-OAuth script execution branch (uses the same interpreter running the web service) - Remove redundant 'import sys' inside the oauth_flow conditional block (sys is already imported at module level; the local import shadows the top-level binding for the entire function scope, which would cause UnboundLocalError if sys were referenced in the else branch on Python 3.12+) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b2aa11e to
118f1c5
Compare
Fix 4 additional subprocess calls that still used 'python3' instead of sys.executable: parameterized action wrapper (line 5150), stdin-param wrapper (line 5211), no-param wrapper (line 5417), and OAuth auth script (line 5524). Ensures plugin actions work in virtualenvs and non-standard Python installations. Addresses CodeRabbit findings on PR ChuckBuilds#277. Co-Authored-By: 5ymb01 <5ymb01@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test ResultsTested on Raspberry Pi (ledpi), Python 3.13.5. Verification
Unit TestsNote: OAuth redirect flow not tested (no OAuth plugin currently configured on test Pi). The code path uses the same |
Reconcile squash-merged PRs (ChuckBuilds#277, ChuckBuilds#290, ChuckBuilds#291) from upstream. Resolve conflict in vegas_mode/coordinator.py: keep both the interrupt check callback (upstream) and inline cycle restart (Dev). Co-Authored-By: 5ymb01 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reconcile squash-merged PRs (ChuckBuilds#277, ChuckBuilds#290, ChuckBuilds#291) from upstream. Resolve conflict in vegas_mode/coordinator.py: keep both the interrupt check callback (upstream) and inline cycle restart (wip). Co-Authored-By: 5ymb01 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Description
execute_plugin_actionhardcodes'python3'in subprocess calls, which breaks in virtualenvs or when the system Python binary has a different name. Also,import sysinside a conditional block shadowed the module-level import.Type of Change
Changes
['python3', ...]subprocess calls with[sys.executable, ...]:import sysfrom inside theoauth_flowconditional blockWhy this matters
sys.executablealways points to the interpreter running the current process, regardless of system naming or virtualenv configurationUnboundLocalErrorriskTesting
Test Plan
sys.executableresolves to the correct Python interpreter` resolves to the correct Python interpreterChecklist
Author: @5ymb01
AI Assistant: Claude Opus 4.6 (Anthropic)
🤖 Generated with Claude Code