Skip to content

Comments

fix: add pyenv shims to PATH on macOS#813

Open
whatevertogo wants to merge 1 commit intoCoplayDev:betafrom
whatevertogo:fix/pyenv-path-macos
Open

fix: add pyenv shims to PATH on macOS#813
whatevertogo wants to merge 1 commit intoCoplayDev:betafrom
whatevertogo:fix/pyenv-path-macos

Conversation

@whatevertogo
Copy link
Contributor

@whatevertogo whatevertogo commented Feb 23, 2026

Description

Add ~/.pyenv/shims to the augmented PATH in MacOSPlatformDetector so that Python installed via pyenv can be found when Unity is launched from Dock/Spotlight on macOS.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

  • Added Path.Combine(homeDir, ".pyenv", "shims") to GetPathAdditions() in MacOSPlatformDetector.cs
  • The pyenv shims path is placed first in the array so it takes priority when present

Testing/Screenshots/Recordings

This is a minimal one-line change. Testing requires:

  1. macOS system with pyenv installed
  2. Python 3.10+ installed via pyenv
  3. Unity launched from Dock/Spotlight (not terminal)
  4. Verify MCP for Unity can detect Python correctly

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual updates following the guide at tools/UPDATE_DOCS.md

Related 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:

  • Include the pyenv shims directory in the macOS PATH additions so Python/uv installed via pyenv can be detected when Unity is launched from Dock or Spotlight.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Python/uv detection on macOS when launching Unity from Dock or Spotlight

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>
Copilot AI review requested due to automatic review settings February 23, 2026 08:21
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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 PATH

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Ensure macOS PATH augmentation includes pyenv shims with highest priority for Python discovery.
  • Extend GetPathAdditions() to prepend the ~/.pyenv/shims directory to the list of PATH additions derived from the user’s home directory.
  • Keep existing Homebrew and system PATH entries unchanged and ordered after the new pyenv shims entry so they remain fallback locations for Python.
MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#812 Add the pyenv shims directory (~/.pyenv/shims) to the augmented PATH in MacOSPlatformDetector.GetPathAdditions(), placing it at the beginning of the list so Python installed via pyenv is discoverable when Unity is launched from Dock/Spotlight.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

The change adds the pyenv shims directory (~/.pyenv/shims) to the PATH augmentation in the macOS platform detector, enabling Python discovery when Unity Editor is launched from Dock or Spotlight rather than from a terminal.

Changes

Cohort / File(s) Summary
macOS Platform Detector
MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs
Added ~/.pyenv/shims to the PATH additions array to enable Python/uv detection when Unity is launched via GUI (Dock/Spotlight) on macOS systems using pyenv.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🐰 Hop hop, a path appears!
Pyenv shims now shimmer clear,
When Dock-launched, Python's found at last,
No terminal dance—the die is cast!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding pyenv shims to PATH on macOS, which is the core objective of this bug fix.
Description check ✅ Passed The description is comprehensive and well-structured, covering all major template sections including description, type of change, changes made, testing requirements, and related issues. Minor documentation checkbox is empty, which is appropriate for this change.
Linked Issues check ✅ Passed The pull request directly addresses issue #812 by adding ~/.pyenv/shims to GetPathAdditions() in MacOSPlatformDetector.cs, exactly as proposed, enabling Python detection when Unity is launched from Dock/Spotlight.
Out of Scope Changes check ✅ Passed The change is narrowly scoped and directly addresses the linked issue; only one file (MacOSPlatformDetector.cs) is modified with a minimal one-line addition to the PATH array, with no extraneous changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/shims to the augmented PATH in MacOSPlatformDetector.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
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs (1)

191-191: Add ~/.pyenv/bin alongside 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 the pyenv binary on PATH. For users who installed pyenv via Homebrew, pyenv lives at /opt/homebrew/bin/pyenv (already covered). However, for users who installed pyenv manually (the official recommended method via git clone), pyenv lives at ~/.pyenv/bin/pyenv — a path not present in the current array. Without it, the shim executes, fails to find pyenv, and the detection silently falls through.

♻️ Proposed fix: add ~/.pyenv/bin
         return 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.
ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95b6ddb and fd6934e.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Dependencies/PlatformDetectors/MacOSPlatformDetector.cs

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.

Python not found on macOS when using pyenv (Unity launched from Dock/Spotlight)

1 participant