Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 4, 2025

This PR resolves a significant performance issue where PET fails when encountering pyenv shims in the PATH environment variable.

Problem

When pyenv shims are present in PATH, PET attempts to execute them directly to gather Python environment information. However, pyenv shims are shell scripts that require proper environment context to function correctly. When executed directly by PET, they:

  • Produce empty output without the expected JSON separator
  • Generate error messages like: Python Execution for "/path/.pyenv/shims/python3.10" produced an output "" without a separator
  • Cause significant performance degradation (3542ms vs 173ms when shims are excluded from PATH)

Solution

Added pyenv shim detection logic in pet-python-utils/src/env.rs that identifies and skips pyenv shims before attempting to execute them:

Detection Methods

  1. Path-based detection: Checks if the executable path contains /.pyenv/shims/
  2. Content-based detection: Reads the file content to look for pyenv-specific patterns (PYENV_ROOT, pyenv, exec)

Implementation Details

  • Added is_pyenv_shim() function with comprehensive detection logic
  • Modified get_interpreter_details() to skip detected shims early in the process
  • Added trace logging for debugging when shims are detected and skipped
  • Exported the function for potential use by other parts of the codebase

Testing

  • Added comprehensive test suite in pyenv_shim_test.rs covering both detection methods
  • Verified that actual Python environments are still discovered correctly via the PyEnv locator
  • Manual testing confirms elimination of error messages and performance improvements
  • All existing tests continue to pass

Impact

  • Performance: Eliminates timeouts and failed execution attempts on pyenv shims
  • Reliability: No more error spam when pyenv shims are in PATH
  • Functionality: PyEnv locator continues to work correctly for discovering actual Python environments
  • Backward compatibility: No breaking changes to existing functionality

The fix maintains the principle mentioned in the codebase documentation: "Avoid spawning processes" when they won't provide useful information.

Fixes #238.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] PET fails with pyenv shims Fix PET failures with pyenv shims by detecting and skipping them Sep 4, 2025
@Copilot Copilot AI requested a review from DonJayamanne September 4, 2025 01:51
Copilot finished work on behalf of DonJayamanne September 4, 2025 01:51
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.

PET fails with pyenv shims
2 participants