Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down