Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ export async function createNamedCondaEnvironment(
},
async () => {
try {
const bin = os.platform() === 'win32' ? 'python.exe' : 'python';
const bin = os.platform() === 'win32' ? 'python.exe' : path.join('bin', 'python');
const output = await runCondaExecutable(runArgs);
log.info(output);

Expand Down Expand Up @@ -1166,7 +1166,7 @@ export async function createPrefixCondaEnvironment(
},
async () => {
try {
const bin = os.platform() === 'win32' ? 'python.exe' : 'python';
const bin = os.platform() === 'win32' ? 'python.exe' : path.join('bin', 'python');
const output = await runCondaExecutable(runArgs);
log.info(output);
const version = await getVersion(prefix);
Expand Down
67 changes: 67 additions & 0 deletions src/test/managers/conda/condaUtils.pythonExePath.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import assert from 'assert';
import * as path from 'path';
import * as sinon from 'sinon';
import { EnvironmentManager } from '../../../api';
import { CondaEnvManager } from '../../../managers/conda/condaEnvManager';
import { getNamedCondaPythonInfo, getPrefixesCondaPythonInfo } from '../../../managers/conda/condaUtils';
import { NativePythonFinder } from '../../../managers/common/nativePythonFinder';
import * as platformUtils from '../../../common/utils/platformUtils';

suite('Conda Python executable path construction', () => {
let isWindowsStub: sinon.SinonStub;
let mockManager: EnvironmentManager;

setup(() => {
mockManager = new CondaEnvManager(
{} as NativePythonFinder,
{} as any,
{ info: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } as any,
);
});

teardown(() => {
sinon.restore();
});

test('getNamedCondaPythonInfo: executable path uses bin/python on non-Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false);
const prefix = '/home/user/miniconda3/envs/myenv';
const executable = path.posix.join(prefix, 'bin', 'python');
const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', '/usr/bin/conda', mockManager);

assert.ok(
info.execInfo.run.executable.includes(path.join('bin', 'python')) ||
info.execInfo.run.executable.endsWith('python'),
`executable should contain bin/python, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});

test('getPrefixesCondaPythonInfo: executable path uses bin/python on non-Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(false);
const prefix = '/home/user/projects/.conda';
const executable = path.posix.join(prefix, 'bin', 'python');
const info = await getPrefixesCondaPythonInfo(prefix, executable, '3.12.0', '/usr/bin/conda', mockManager);

assert.ok(
info.execInfo.run.executable.includes(path.join('bin', 'python')) ||
info.execInfo.run.executable.endsWith('python'),
`executable should contain bin/python, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});

test('getNamedCondaPythonInfo: executable path uses python.exe on Windows', async () => {
isWindowsStub = sinon.stub(platformUtils, 'isWindows').returns(true);
const prefix = 'C:\\Users\\user\\miniconda3\\envs\\myenv';
const executable = path.win32.join(prefix, 'python.exe');
const info = await getNamedCondaPythonInfo('myenv', prefix, executable, '3.12.0', 'C:\\conda\\conda.exe', mockManager);

assert.ok(
info.execInfo.run.executable.endsWith('python.exe'),
`executable should end with python.exe, got: ${info.execInfo.run.executable}`,
);
isWindowsStub.restore();
});
});
Loading