Skip to content

Commit 2fe7780

Browse files
committed
fix: use conda.sh for Git Bash activation on Windows (Fixes #1247)
1 parent 33e8098 commit 2fe7780

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/managers/conda/condaSourcingUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import * as path from 'path';
66
import { traceError, traceInfo, traceVerbose } from '../../common/logging';
77
import { isWindows } from '../../common/utils/platformUtils';
88

9+
/**
10+
* Indices for shell-specific sourcing scripts in shellSourcingScripts array.
11+
* The array is populated by findShellSourcingScripts in this order.
12+
*/
13+
export const SHELL_SOURCING_SCRIPT_INDEX = {
14+
PS1: 0, // PowerShell hook (conda-hook.ps1)
15+
SH: 1, // Bash/sh script (conda.sh)
16+
CMD: 2, // CMD batch file (activate.bat)
17+
} as const;
18+
919
/**
1020
* Represents the status of conda sourcing in the current environment
1121
*/

src/managers/conda/condaUtils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { selectFromCommonPackagesToInstall } from '../common/pickers';
5555
import { Installable } from '../common/types';
5656
import { shortVersion, sortEnvironments } from '../common/utils';
5757
import { CondaEnvManager } from './condaEnvManager';
58-
import { getCondaHookPs1Path, getLocalActivationScript } from './condaSourcingUtils';
58+
import { getCondaHookPs1Path, getLocalActivationScript, SHELL_SOURCING_SCRIPT_INDEX } from './condaSourcingUtils';
5959
import { createStepBasedCondaFlow } from './condaStepBasedFlow';
6060

6161
export const CONDA_PATH_KEY = `${ENVS_EXTENSION_ID}:conda:CONDA_PATH`;
@@ -512,10 +512,16 @@ async function buildShellActivationMapForConda(
512512
// P3: Handle Windows specifically ;this is carryover from vscode-python
513513
if (isWindows()) {
514514
logs.push('✓ Using Windows-specific activation configuration');
515+
// Get conda.sh for bash-based shells (Git Bash, WSL bash)
516+
const condaShPath = envManager.sourcingInformation.shellSourcingScripts?.[SHELL_SOURCING_SCRIPT_INDEX.SH];
517+
if (!condaShPath) {
518+
logs.push('conda.sh not found, falling back to global sourcing script for bash activation');
519+
}
515520
shellMaps = await windowsExceptionGenerateConfig(
516521
preferredSourcingPath,
517522
envIdentifier,
518523
envManager.sourcingInformation.condaFolder,
524+
condaShPath,
519525
);
520526
return shellMaps;
521527
}
@@ -580,6 +586,7 @@ async function windowsExceptionGenerateConfig(
580586
sourceInitPath: string,
581587
prefix: string,
582588
condaFolder: string,
589+
condaShPath?: string,
583590
): Promise<ShellCommandMaps> {
584591
const shellActivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
585592
const shellDeactivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
@@ -593,7 +600,10 @@ async function windowsExceptionGenerateConfig(
593600
const pwshActivate = [{ executable: activation }, { executable: 'conda', args: ['activate', quotedPrefix] }];
594601
const cmdActivate = [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', quotedPrefix] }];
595602

596-
const bashActivate = [{ executable: 'source', args: [sourceInitPath.replace(/\\/g, '/'), quotedPrefix] }];
603+
// Use conda.sh for bash-based shells (Git Bash) instead of activate.bat
604+
// conda.sh is the proper initialization script for bash shells
605+
const bashSourcePath = condaShPath ?? sourceInitPath;
606+
const bashActivate = [{ executable: 'source', args: [bashSourcePath.replace(/\\/g, '/'), quotedPrefix] }];
597607
traceVerbose(
598608
`Windows activation commands:
599609
PowerShell: ${JSON.stringify(pwshActivate)},

0 commit comments

Comments
 (0)