fix: add pyenv shims to PATH on macOS#813
fix: add pyenv shims to PATH on macOS#813whatevertogo wants to merge 1 commit intoCoplayDev:betafrom
Conversation
When Unity is launched from Dock/Spotlight on macOS, GUI applications do not inherit the shell's PATH from .zshrc/.bashrc. This caused MCP for Unity to fail finding Python installed via pyenv. Add ~/.pyenv/shims to the augmented PATH in MacOSPlatformDetector so Python can be found regardless of how Unity is launched. Fixes CoplayDev#812 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds the pyenv shims directory to the macOS PATH augmentation logic so that Python installed via pyenv is discoverable when Unity is launched from GUI contexts (Dock/Spotlight). Sequence diagram for macOS Python detection with pyenv shims in PATHsequenceDiagram
actor MacUser
participant UnityApp
participant MCPForUnity
participant MacOSPlatformDetector
participant Environment
MacUser->>UnityApp: Launch from Dock or Spotlight
UnityApp->>MCPForUnity: Initialize MCP for Unity
MCPForUnity->>MacOSPlatformDetector: DetectPython()
MacOSPlatformDetector->>MacOSPlatformDetector: GetPathAdditions()
MacOSPlatformDetector->>Environment: GetFolderPath(UserProfile)
Environment-->>MacOSPlatformDetector: homeDir
MacOSPlatformDetector->>MacOSPlatformDetector: Build PATH additions array
Note right of MacOSPlatformDetector: First entry: homeDir/.pyenv/shims
MacOSPlatformDetector->>Environment: Combine PATH additions with system PATH
Environment-->>MacOSPlatformDetector: Augmented PATH
MacOSPlatformDetector->>Environment: Locate python executable
Environment-->>MacOSPlatformDetector: python path from pyenv shims
MacOSPlatformDetector-->>MCPForUnity: Return detected python
MCPForUnity-->>UnityApp: Python available
UnityApp-->>MacUser: MCP for Unity ready with Python
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📝 WalkthroughWalkthroughThe change adds the pyenv shims directory ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Hey - I've left some high level feedback:
- Consider using the
PYENV_ROOTenvironment variable (falling back to~/.pyenv) when constructing the shims path, so setups with a custom pyenv location are also supported. - It may be worth skipping non-existent directories when augmenting PATH, so that a missing
~/.pyenv/shimsdoes not end up as a dead entry in the PATH list.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using the `PYENV_ROOT` environment variable (falling back to `~/.pyenv`) when constructing the shims path, so setups with a custom pyenv location are also supported.
- It may be worth skipping non-existent directories when augmenting PATH, so that a missing `~/.pyenv/shims` does not end up as a dead entry in the PATH list.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This PR fixes Python detection for macOS users who have installed Python via pyenv when Unity is launched from the Dock or Spotlight. The root cause is that GUI applications on macOS don't inherit the interactive shell's PATH, so the pyenv shims directory needs to be explicitly added to the augmented PATH.
Changes:
- Added
~/.pyenv/shimsto the augmented PATH inMacOSPlatformDetector.GetPathAdditions() - The path is placed first in the array to prioritize pyenv-managed Python installations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); | ||
| return new[] | ||
| { | ||
| Path.Combine(homeDir, ".pyenv", "shims"), // pyenv: Python/uv when Unity is launched from Dock/Spotlight |
There was a problem hiding this comment.
Consider making the comment more specific: "pyenv-managed Python/uv when Unity is launched from Dock/Spotlight". This clarifies that this path is specifically for pyenv installations, not all Python installations. This helps future maintainers understand why this particular path is included.
| Path.Combine(homeDir, ".pyenv", "shims"), // pyenv: Python/uv when Unity is launched from Dock/Spotlight | |
| Path.Combine(homeDir, ".pyenv", "shims"), // pyenv-managed Python/uv when Unity is launched from Dock/Spotlight |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs (1)
191-191: Add~/.pyenv/binalongside the shims path to support non-Homebrew pyenv installs.pyenv shims are bash wrappers that internally call
exec pyenv exec <command>. When a shim runs, the child bash process must be able to find thepyenvbinary on PATH. For users who installed pyenv via Homebrew,pyenvlives at/opt/homebrew/bin/pyenv(already covered). However, for users who installed pyenv manually (the official recommended method viagit clone),pyenvlives at~/.pyenv/bin/pyenv— a path not present in the current array. Without it, the shim executes, fails to findpyenv, and the detection silently falls through.♻️ Proposed fix: add
~/.pyenv/binreturn new[] { Path.Combine(homeDir, ".pyenv", "shims"), // pyenv: Python/uv when Unity is launched from Dock/Spotlight + Path.Combine(homeDir, ".pyenv", "bin"), // pyenv binary itself (needed by shims when pyenv is not installed via Homebrew) "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin", Path.Combine(homeDir, ".local", "bin") };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs` at line 191, The MacOSPlatformDetector currently adds Path.Combine(homeDir, ".pyenv", "shims") to PATH but misses the actual pyenv binary location for non-Homebrew installs; update the PATH entries in MacOSPlatformDetector.cs (the array where Path.Combine(homeDir, ".pyenv", "shims") is added) to also include Path.Combine(homeDir, ".pyenv", "bin") so manual/git-clone pyenv installs can be found by shims; ensure the new entry is added alongside the existing shims entry and preserve ordering/behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs`:
- Line 191: The MacOSPlatformDetector currently adds Path.Combine(homeDir,
".pyenv", "shims") to PATH but misses the actual pyenv binary location for
non-Homebrew installs; update the PATH entries in MacOSPlatformDetector.cs (the
array where Path.Combine(homeDir, ".pyenv", "shims") is added) to also include
Path.Combine(homeDir, ".pyenv", "bin") so manual/git-clone pyenv installs can be
found by shims; ensure the new entry is added alongside the existing shims entry
and preserve ordering/behavior.
Description
Add
~/.pyenv/shimsto the augmented PATH inMacOSPlatformDetectorso that Python installed via pyenv can be found when Unity is launched from Dock/Spotlight on macOS.Type of Change
Changes Made
Path.Combine(homeDir, ".pyenv", "shims")toGetPathAdditions()inMacOSPlatformDetector.csTesting/Screenshots/Recordings
This is a minimal one-line change. Testing requires:
Documentation Updates
tools/UPDATE_DOCS_PROMPT.md(recommended)tools/UPDATE_DOCS.mdRelated Issues
Fixes #812
Additional Notes
Root cause: On macOS, GUI applications launched from Dock/Spotlight do not inherit the interactive shell's PATH (from
.zshrc/.bashrc). The pyenv shims directory (~/.pyenv/shims) was not included in the augmented PATH, causing Python detection to fail for pyenv users.Solution: Add the pyenv shims directory to the augmented PATH. If the user doesn't use pyenv, this directory typically doesn't exist and the resolver continues with the next paths in the list.
Summary by Sourcery
Bug Fixes:
Summary by CodeRabbit