Skip to content

Commit fbd8763

Browse files
author
Kartik Raj
authored
Prefer to use .bat files over .exe for conda on windows (#18771)
* Prefer to use .bat files over .exe for conda on windows * Only build VSIX * Oops * Fix * Run all tests * Add tests
1 parent 091c402 commit fbd8763

File tree

2 files changed

+39
-1
lines changed
  • src

2 files changed

+39
-1
lines changed

src/client/pythonEnvironments/common/environmentManagers/conda.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,34 @@ export class Conda {
354354
.map((line) => path.join(line, suffix));
355355
}
356356

357+
async function getCondaBatFile(file: string) {
358+
const fileDir = path.dirname(file);
359+
const possibleBatch = path.join(fileDir, '..', 'condabin', 'conda.bat');
360+
if (await pathExists(possibleBatch)) {
361+
return possibleBatch;
362+
}
363+
return undefined;
364+
}
365+
357366
// Probe the candidates, and pick the first one that exists and does what we need.
358367
for await (const condaPath of getCandidates()) {
359368
traceVerbose(`Probing conda binary: ${condaPath}`);
360-
const conda = new Conda(condaPath);
369+
let conda = new Conda(condaPath);
361370
try {
362371
await conda.getInfo();
372+
if (getOSType() === OSType.Windows) {
373+
// Prefer to use .bat files over .exe on windows as that is what cmd works best on.
374+
const condaBatFile = await getCondaBatFile(condaPath);
375+
try {
376+
if (condaBatFile) {
377+
const condaBat = new Conda(condaBatFile);
378+
await condaBat.getInfo();
379+
conda = condaBat;
380+
}
381+
} catch (ex) {
382+
traceVerbose('Failed to spawn conda bat file', condaBatFile, ex);
383+
}
384+
}
363385
traceVerbose(`Found conda via filesystem probing: ${condaPath}`);
364386
return conda;
365387
} catch (ex) {

src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ suite('Conda and its environments are located correctly', () => {
245245
await expectConda('/bin/conda');
246246
});
247247

248+
test('Use conda.bat when possible over conda.exe on windows', async () => {
249+
osType = platform.OSType.Windows;
250+
251+
getPythonSetting.withArgs('condaPath').returns('bin/conda');
252+
files = {
253+
bin: {
254+
conda: JSON.stringify(condaInfo('4.8.0')),
255+
},
256+
condabin: {
257+
'conda.bat': JSON.stringify(condaInfo('4.8.0')),
258+
},
259+
};
260+
261+
await expectConda('/condabin/conda.bat');
262+
});
263+
248264
suite('Must find conda in well-known locations', () => {
249265
const condaDirNames = ['Anaconda', 'anaconda', 'Miniconda', 'miniconda'];
250266

0 commit comments

Comments
 (0)