Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 1, 2025

This PR refactors the conda sourcing script detection to improve performance and reliability by moving the search logic from on-demand execution to async initialization during extension startup.

Problem

Previously, conda sourcing scripts (like conda.sh and conda-hook.ps1) were located on-demand within getNamedCondaPythonInfo and getPrefixesCondaPythonInfo functions. This approach had several issues:

  1. Performance: File system checks were performed repeatedly for each environment
  2. Limited search scope: Only checked basic relative paths from conda executable
  3. No profile awareness: Didn't check if conda was already initialized in shell profiles
  4. Missing condaPath setting: Didn't include user-configured conda paths in search

Solution

This implementation moves conda sourcing detection to the extension startup phase and adds comprehensive shell profile checking:

🔍 Async Sourcing Search

  • New searchCondaSourcingInfo() function called during registerCondaFeatures
  • Searches comprehensive list of conda.sh locations including:
    • etc/profile.d/conda.sh
    • shell/etc/profile.d/conda.sh
    • Library/etc/profile.d/conda.sh
    • lib/pythonX.Y/site-packages/conda/shell/etc/profile.d/conda.sh
    • site-packages/conda/shell/etc/profile.d/conda.sh
    • System-level locations (/etc/profile.d/conda.sh, /opt/conda/etc/profile.d/conda.sh, etc.)
  • Includes user-specified condaPath setting in search paths

🐚 Shell Profile Init Detection

  • Checks shell profiles (.bashrc, .zshrc, .config/fish/config.fish) for conda initialization
  • Detects existing conda init using # >>> conda initialize >>> marker
  • Leverages existing shell startup provider infrastructure
  • Stores per-shell initialization status in cache

Performance Optimization

  • Caches all sourcing information for quick retrieval
  • Eliminates repeated file system checks during environment info building
  • getNamedCondaPythonInfo and getPrefixesCondaPythonInfo now use cached data
  • Maintains full backward compatibility with fallback logic

🧪 Test Coverage

  • Added comprehensive unit tests for conda initialization detection
  • Tests cover missing files, empty profiles, and various conda init scenarios
  • All existing tests continue to pass (126 passing)

Example Usage

The changes are transparent to users, but internally the extension now:

  1. At startup: Searches for conda scripts and checks shell profiles
  2. During environment discovery: Uses cached information instead of on-demand file system checks
  3. Shell activation: Provides more reliable sourcing script paths for different shells

Fixes #674.


💡 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 AI changed the title [WIP] Fix Conda Sourcing Search & Add Profile Init Check Fix Conda Sourcing Search & Add Profile Init Check Aug 1, 2025
Copilot AI requested a review from eleanorjboyd August 1, 2025 00:21
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.

Fix Conda Sourcing Search & Add Profile Init Check

2 participants