diff --git a/src/client/pythonEnvironments/common/environmentManagers/conda.ts b/src/client/pythonEnvironments/common/environmentManagers/conda.ts index abd0725ccfb4..cbc03e8698c4 100644 --- a/src/client/pythonEnvironments/common/environmentManagers/conda.ts +++ b/src/client/pythonEnvironments/common/environmentManagers/conda.ts @@ -354,12 +354,34 @@ export class Conda { .map((line) => path.join(line, suffix)); } + async function getCondaBatFile(file: string) { + const fileDir = path.dirname(file); + const possibleBatch = path.join(fileDir, '..', 'condabin', 'conda.bat'); + if (await pathExists(possibleBatch)) { + return possibleBatch; + } + return undefined; + } + // Probe the candidates, and pick the first one that exists and does what we need. for await (const condaPath of getCandidates()) { traceVerbose(`Probing conda binary: ${condaPath}`); - const conda = new Conda(condaPath); + let conda = new Conda(condaPath); try { await conda.getInfo(); + if (getOSType() === OSType.Windows) { + // Prefer to use .bat files over .exe on windows as that is what cmd works best on. + const condaBatFile = await getCondaBatFile(condaPath); + try { + if (condaBatFile) { + const condaBat = new Conda(condaBatFile); + await condaBat.getInfo(); + conda = condaBat; + } + } catch (ex) { + traceVerbose('Failed to spawn conda bat file', condaBatFile, ex); + } + } traceVerbose(`Found conda via filesystem probing: ${condaPath}`); return conda; } catch (ex) { diff --git a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts index 553ef2e5e9d7..a452cd2d2db7 100644 --- a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts +++ b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts @@ -245,6 +245,22 @@ suite('Conda and its environments are located correctly', () => { await expectConda('/bin/conda'); }); + test('Use conda.bat when possible over conda.exe on windows', async () => { + osType = platform.OSType.Windows; + + getPythonSetting.withArgs('condaPath').returns('bin/conda'); + files = { + bin: { + conda: JSON.stringify(condaInfo('4.8.0')), + }, + condabin: { + 'conda.bat': JSON.stringify(condaInfo('4.8.0')), + }, + }; + + await expectConda('/condabin/conda.bat'); + }); + suite('Must find conda in well-known locations', () => { const condaDirNames = ['Anaconda', 'anaconda', 'Miniconda', 'miniconda'];