From 9f6735e761f15f8f664754d4fdf46d58c3c5f1c5 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 26 Sep 2024 16:18:32 -0700 Subject: [PATCH] Prioritize `conda` handler over `pixi` handler (#24198) Related https://github.com/microsoft/vscode-python/issues/24087 --- .../common/process/pythonExecutionFactory.ts | 25 ++++++++++--------- .../pythonExecutionFactory.unit.test.ts | 7 ++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/client/common/process/pythonExecutionFactory.ts b/src/client/common/process/pythonExecutionFactory.ts index 939c91514952..d8401a603d03 100644 --- a/src/client/common/process/pythonExecutionFactory.ts +++ b/src/client/common/process/pythonExecutionFactory.ts @@ -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)) @@ -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); } @@ -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; } } diff --git a/src/test/common/process/pythonExecutionFactory.unit.test.ts b/src/test/common/process/pythonExecutionFactory.unit.test.ts index e31a9e4d900e..dd0061b79d63 100644 --- a/src/test/common/process/pythonExecutionFactory.unit.test.ts +++ b/src/test/common/process/pythonExecutionFactory.unit.test.ts @@ -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', @@ -87,10 +88,15 @@ suite('Process - PythonExecutionFactory', () => { let executionService: typemoq.IMock; 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); @@ -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 () => {