-
-
Notifications
You must be signed in to change notification settings - Fork 691
fix: handle Python paths with spaces correctly #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughReorders Python command parsing to treat path-like strings (contain / or \ and not starting with -) before existence checks, extends allowed path regexes for macOS/Windows locations, and swaps shell-based Changes
Sequence Diagram(s)sequenceDiagram
%% Styling for clarity
participant App as Frontend
participant Detector as python-detector
participant Child as child_process (execFileSync)
participant OS as System FS / PATH
App->>Detector: parsePythonCommand(rawCommand)
Detector-->>App: { cmd, args, isPathLike }
alt isPathLike == true
App->>Child: execFileSync(cmd, args, shell:false, timeout)
Child->>OS: spawn executable directly
OS-->>Child: executable path or error
Child-->>App: stdout / resolved path or error
else not path-like
App->>Child: execFileSync(cmd, args, shell:false, timeout)
Child->>OS: resolve via PATH / system
OS-->>Child: resolved path or error
Child-->>App: stdout / resolved path or error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (3)apps/frontend/src/**/*.{ts,tsx,jsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
apps/frontend/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
apps/frontend/**/*.{ts,tsx}⚙️ CodeRabbit configuration file
Files:
🧬 Code graph analysis (1)apps/frontend/src/main/python-env-manager.ts (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (6)
Comment |
|
All contributors have signed the CLA. Thank you! |
Summary of ChangesHello @abe238, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where Python paths containing spaces, particularly those found in Electron application data directories on macOS and Windows, were causing Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively resolves the issue of handling Python paths with spaces, which was causing errors on platforms like macOS. The core logic change in parsePythonCommand to prioritize path structure over file existence is a solid fix. Additionally, switching to execFileSync from execSync is a great improvement for both security and robustness, preventing shell interpretation issues. The new regex patterns for Electron's userData paths on both macOS and Windows are also a necessary addition. I've included a couple of suggestions to consolidate similar regular expressions for improved maintainability. Overall, this is a well-executed fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
apps/frontend/src/main/python-detector.tsapps/frontend/src/main/python-env-manager.ts
🧰 Additional context used
📓 Path-based instructions (3)
apps/frontend/src/**/*.{ts,tsx,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always use i18n translation keys for all user-facing text in the frontend instead of hardcoded strings
Files:
apps/frontend/src/main/python-env-manager.tsapps/frontend/src/main/python-detector.ts
apps/frontend/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
useTranslation()hook with namespace prefixes (e.g., 'navigation:items.key') for accessing translation strings in React components
Files:
apps/frontend/src/main/python-env-manager.tsapps/frontend/src/main/python-detector.ts
apps/frontend/**/*.{ts,tsx}
⚙️ CodeRabbit configuration file
apps/frontend/**/*.{ts,tsx}: Review React patterns and TypeScript type safety.
Check for proper state management and component composition.
Files:
apps/frontend/src/main/python-env-manager.tsapps/frontend/src/main/python-detector.ts
🪛 GitHub Actions: CI
apps/frontend/src/main/python-env-manager.ts
[error] 205-205: TypeScript error: Cannot find name 'parsePythonCommand'.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: CodeQL (javascript-typescript)
- GitHub Check: CodeQL (python)
🔇 Additional comments (4)
apps/frontend/src/main/python-detector.ts (3)
211-213: Excellent documentation enhancement.The added emphasis on handling paths with spaces is clear and directly addresses the root cause described in the PR. This will help prevent future regressions.
237-255: Core fix correctly implements path-with-spaces handling.The reordering of checks is the key improvement:
- Path separator detection now happens before existence checks
- Paths with separators are returned as-is without splitting on spaces
- This correctly handles venv paths that don't exist yet during setup
The logic is sound and directly addresses the root cause of the ENOENT errors.
306-309: Pattern coverage is correct—no changes needed.The added patterns accurately match Electron userData paths:
- macOS:
/Users/<user>/Library/Application Support/<app>/is the standard userData location; non-standard home directories are not a practical concern.- Windows:
AppData\Roaming\<app>\is the correct userData location;AppData\Localis used only for system Python installations (already handled by line 318).- App name matching:
[^/]+and[^\\]+correctly capture all app names while preventing directory traversal.The generic patterns at lines 313–315 provide fallback coverage for Linux and other venv naming variations.
apps/frontend/src/main/python-env-manager.ts (1)
204-210: Correct fix for shell interpretation issues with spaces.The change from
execSynctoexecFileSyncwithshell: falseis the right approach:
- Prevents the shell from splitting paths at spaces
- Uses
parsePythonCommandto correctly parse the command- Maintains the same 5-second timeout for safety
This change works correctly once the missing import is added (see previous comment).
Note: This comment assumes the missing
parsePythonCommandimport will be added as suggested in the previous review comment.
- Updated parsePythonCommand to check for path separators BEFORE existsSync to properly handle paths that may not exist yet - Added macOS Application Support and Windows AppData patterns to ALLOWED_PATH_PATTERNS for Electron userData venv paths - Changed python-env-manager to use execFileSync instead of execSync to avoid shell interpretation issues with spaces Fixes spawn ENOENT errors when venv Python path contains spaces, e.g., /Users/user/Library/Application Support/App/python-venv/bin/python 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Abe Diaz (@abe238) <[email protected]>
54bb603 to
890704c
Compare
AlexMadera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Auto Claude PR Review
Merge Verdict: ✅ READY TO MERGE
No blocking issues found
Risk Assessment
| Factor | Level | Notes |
|---|---|---|
| Complexity | Low | Based on lines changed |
| Security Impact | Low | Based on security findings |
| Scope Coherence | Good | Based on structural review |
Findings Summary
- Medium: 1 issue(s)
- Low: 3 issue(s)
Generated by Auto Claude PR Review
Findings (4 selected of 4 total)
🟡 [MEDIUM] getPythonVersion still uses execSync with string interpolation
📁 apps/frontend/src/main/python-detector.ts:130
The getPythonVersion function at line 130 still uses execSync(${pythonCmd} --version) which could fail for paths containing spaces. This is inconsistent with the PR's goal of fixing space handling. While this function is primarily called with simple command names, the pattern should be updated for consistency with the execFileSync approach used elsewhere.
Suggested fix:
Update getPythonVersion to use parsePythonCommand() and execFileSync similar to verifyIsPython(): `const [cmd, args] = parsePythonCommand(pythonCmd); const version = execFileSync(cmd, [...args, '--version'], { stdio: 'pipe', timeout: 5000, windowsHide: true, shell: false }).toString().trim();`
🔵 [LOW] Edge case regression for files with spaces in name
📁 apps/frontend/src/main/python-detector.ts:234
The new logic order (checking path separators before existsSync) introduces a theoretical regression: if a user has an actual file literally named 'py -3' in the current directory, it would now be incorrectly split into ['py', ['-3']] instead of being recognized as a single file. This is an extremely unlikely scenario in practice.
Suggested fix:
Consider adding a comment documenting this behavioral change, or add a final existsSync check for non-path-like strings before splitting. Given the low probability of this edge case, this is acceptable for now.
🔵 [LOW] Regex patterns use permissive character class for app names
📁 apps/frontend/src/main/python-detector.ts:305
The new regex patterns use [^/]+ and [^\\]+ which allow any characters except path separators in the username and app name positions. While this works correctly and the existing path.normalize() and '..' check provide protection, using a more restrictive character class like [a-zA-Z0-9_\-. ]+ would reduce attack surface.
Suggested fix:
Consider tightening the regex to `/^\/Users\/[a-zA-Z0-9_\-. ]+\/Library\/Application Support\/[a-zA-Z0-9_\-. ]+\/python-venv\/bin\/python\d*(\.\d+)?$/` for defense in depth. The current pattern is acceptable given the existing validation layer.
🔵 [LOW] No unit tests for parsePythonCommand with space-containing paths
📁 apps/frontend/src/main/python-detector.ts:215
The PR adds critical logic for handling paths with spaces, but there are no unit tests specifically testing scenarios like '/Users/user/Library/Application Support/App/python-venv/bin/python'. The existing subprocess-spawn.test.ts tests the spawning but not the path parsing edge cases.
Suggested fix:
Add unit tests for parsePythonCommand covering: 1) paths with spaces that exist, 2) paths with spaces that don't exist yet, 3) simple commands like 'py -3', 4) Windows paths with spaces. This ensures the fix doesn't regress.
This review was generated by Auto Claude.
|
I have read the CLA Document and I hereby sign the CLA |
- Add missing parsePythonCommand import (CodeRabbit critical) - Consolidate macOS Application Support regex patterns (Gemini) - Consolidate Windows AppData Roaming regex patterns (Gemini) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
AlexMadera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Auto Claude PR Review
Merge Verdict: ✅ READY TO MERGE
No blocking issues found
Risk Assessment
| Factor | Level | Notes |
|---|---|---|
| Complexity | Low | Based on lines changed |
| Security Impact | Low | Based on security findings |
| Scope Coherence | Good | Based on structural review |
Findings Summary
- Medium: 1 issue(s)
- Low: 3 issue(s)
Generated by Auto Claude PR Review
No findings selected for this review.
This review was generated by Auto Claude.
Summary
parsePythonCommandto check for path separators BEFOREexistsSyncto properly handle paths that may not exist yetALLOWED_PATH_PATTERNSfor Electron userData venv pathspython-env-managerto useexecFileSyncinstead ofexecSyncto avoid shell interpretation issues with spacesProblem
When using the packaged app on macOS, the venv Python path contains spaces:
/Users/user/Library/Application Support/App/python-venv/bin/pythonThis was causing
spawn ENOENTerrors during merge operations because the path was being incorrectly split at the space character.Root Cause
The
parsePythonCommandfunction was checkingexistsSync()before checking if the path looked like a file path. If the file didn't exist (e.g., during initial setup), and the path wasn't recognized as a path, it would fall through to splitting on spaces.Fix
/or\) FIRST, before checking file existence/Users/<user>/Library/Application Support/<app>/python-venv/bin/pythonC:\Users\<user>\AppData\Roaming\<app>\python-venv\Scripts\python.exepython-env-manager.tsto useexecFileSyncwithshell: falseto avoid shell interpretation issuesTest Plan
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.