Skip to content

Commit

Permalink
Prioritize conda handler over pixi handler (#24198)
Browse files Browse the repository at this point in the history
Related #24087
  • Loading branch information
karthiknadig committed Sep 26, 2024
1 parent 710d3c8 commit 9f6735e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/client/common/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
}
const processService: IProcessService = await this.processServiceFactory.create(options.resource);

const pixiExecutionService = await this.createPixiExecutionService(pythonPath, processService);
if (pixiExecutionService) {
return pixiExecutionService;
}

const condaExecutionService = await this.createCondaExecutionService(pythonPath, processService);
if (condaExecutionService) {
return condaExecutionService;
}

const pixiExecutionService = await this.createPixiExecutionService(pythonPath, processService);
if (pixiExecutionService) {
return pixiExecutionService;
}

const windowsStoreInterpreterCheck = this.pyenvs.isMicrosoftStoreInterpreter.bind(this.pyenvs);

const env = (await windowsStoreInterpreterCheck(pythonPath))
Expand Down Expand Up @@ -122,15 +122,16 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
processService.on('exec', this.logger.logProcess.bind(this.logger));
this.disposables.push(processService);

const condaExecutionService = await this.createCondaExecutionService(pythonPath, processService);
if (condaExecutionService) {
return condaExecutionService;
}

const pixiExecutionService = await this.createPixiExecutionService(pythonPath, processService);
if (pixiExecutionService) {
return pixiExecutionService;
}

const condaExecutionService = await this.createCondaExecutionService(pythonPath, processService);
if (condaExecutionService) {
return condaExecutionService;
}
const env = createPythonEnv(pythonPath, processService, this.fileSystem);
return createPythonService(processService, env);
}
Expand Down Expand Up @@ -161,11 +162,11 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
}

const env = await createPixiEnv(pixiEnvironment, processService, this.fileSystem);
if (!env) {
return undefined;
if (env) {
return createPythonService(processService, env);
}

return createPythonService(processService, env);
return undefined;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/common/process/pythonExecutionFactory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ServiceContainer } from '../../../client/ioc/container';
import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info';
import { IInterpreterAutoSelectionService } from '../../../client/interpreter/autoSelection/types';
import { Conda, CONDA_RUN_VERSION } from '../../../client/pythonEnvironments/common/environmentManagers/conda';
import * as pixi from '../../../client/pythonEnvironments/common/environmentManagers/pixi';

const pythonInterpreter: PythonEnvironment = {
path: '/foo/bar/python.exe',
Expand Down Expand Up @@ -87,10 +88,15 @@ suite('Process - PythonExecutionFactory', () => {
let executionService: typemoq.IMock<IPythonExecutionService>;
let autoSelection: IInterpreterAutoSelectionService;
let interpreterPathExpHelper: IInterpreterPathService;
let getPixiEnvironmentFromInterpreterStub: sinon.SinonStub;
const pythonPath = 'path/to/python';
setup(() => {
sinon.stub(Conda, 'getConda').resolves(new Conda('conda'));
sinon.stub(Conda.prototype, 'getInterpreterPathForEnvironment').resolves(pythonPath);

getPixiEnvironmentFromInterpreterStub = sinon.stub(pixi, 'getPixiEnvironmentFromInterpreter');
getPixiEnvironmentFromInterpreterStub.resolves(undefined);

activationHelper = mock(EnvironmentActivationService);
processFactory = mock(ProcessServiceFactory);
configService = mock(ConfigurationService);
Expand Down Expand Up @@ -336,6 +342,7 @@ suite('Process - PythonExecutionFactory', () => {
} else {
verify(pyenvs.getCondaEnvironment(interpreter!.path)).once();
}
expect(getPixiEnvironmentFromInterpreterStub.notCalled).to.be.equal(true);
});

test('Ensure `createActivatedEnvironment` returns a PythonExecutionService instance if createCondaExecutionService() returns undefined', async () => {
Expand Down

0 comments on commit 9f6735e

Please sign in to comment.