Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 21, 2025

Fix wrong activate command with PowerShell for conda

Fixed the issue in the windowsExceptionGenerateConfig function in condaUtils.ts.

Problem

When using PowerShell with conda, the activation command incorrectly tries to execute the conda-hook.ps1 script directly instead of dot-sourcing it. This results in commands like:

/path/to/conda-hook.ps1; conda activate myenv

Instead of the correct PowerShell syntax:

. /path/to/conda-hook.ps1; conda activate myenv

Solution

Modified the PowerShell activation logic to properly dot-source the conda-hook.ps1 script when available:

// For PowerShell, we need to dot-source the conda-hook.ps1 script if available
const pwshActivate = ps1Hook 
    ? [{ executable: '.', args: [ps1Hook] }, { executable: 'conda', args: ['activate', prefix] }]
    : [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', prefix] }];

Changes Made

  • PowerShell activation: Now uses dot-sourcing operator (.) when conda-hook.ps1 is available
  • Fallback behavior: Maintains existing behavior when PowerShell hook is not found
  • Other shells unchanged: CMD and Bash activation commands remain unaffected
  • Added tests: Created comprehensive tests to validate PowerShell command formatting

Testing

  • ✅ All existing tests pass (132 passing)
  • ✅ Added 4 new tests for PowerShell conda activation scenarios
  • ✅ Code passes linting requirements
  • ✅ No breaking changes to other shell types

The fix ensures PowerShell will now generate correct activation commands like (. /path/to/conda-hook.ps1) ; (conda activate myenv) instead of the incorrect syntax that was causing failures.

Fixes #766.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
@eleanorjboyd
Copy link
Member

@copilot try again

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 22, 2025

@copilot try again

Fixed in commit 4f0a569. The PowerShell conda activation now properly dot-sources the conda-hook.ps1 script using the . operator instead of trying to execute it directly. This addresses the issue shown in the image where PowerShell was using incorrect source syntax.

Key changes:

  • When conda-hook.ps1 is available: (. /path/to/conda-hook.ps1) ; (conda activate myenv)
  • Fallback when not available: (/path/to/activate.bat) ; (conda activate myenv)

Added tests to validate the fix and ensure no regressions.

@Copilot Copilot AI changed the title [WIP] Wrong activate command with powershell with conda Fix wrong activate command with powershell with conda Sep 22, 2025
@eleanorjboyd eleanorjboyd added the bug Issue identified by VS Code Team member as probable bug label Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong activate command with powershell with conda

2 participants