From 3dd52fcfdf9a8df9cc327f8869b8c825f4308a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Correia?= Date: Tue, 11 Feb 2025 14:53:58 +0000 Subject: [PATCH 1/2] Always use environment path when running conda environment commands --- .../common/environmentManagers/conda.ts | 7 ++----- .../common/process/pythonEnvironment.unit.test.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/client/pythonEnvironments/common/environmentManagers/conda.ts b/src/client/pythonEnvironments/common/environmentManagers/conda.ts index 5301f82eda18..2fd3f3207fc5 100644 --- a/src/client/pythonEnvironments/common/environmentManagers/conda.ts +++ b/src/client/pythonEnvironments/common/environmentManagers/conda.ts @@ -564,11 +564,8 @@ export class Conda { return undefined; } const args = []; - if (env.name) { - args.push('-n', env.name); - } else { - args.push('-p', env.prefix); - } + args.push('-p', env.prefix); + const python = [ forShellExecution ? this.shellCommand : this.command, 'run', diff --git a/src/test/common/process/pythonEnvironment.unit.test.ts b/src/test/common/process/pythonEnvironment.unit.test.ts index f4b11bb97cd5..a2cca66d08be 100644 --- a/src/test/common/process/pythonEnvironment.unit.test.ts +++ b/src/test/common/process/pythonEnvironment.unit.test.ts @@ -284,7 +284,7 @@ suite('CondaEnvironment', () => { teardown(() => sinon.restore()); - test('getExecutionInfo with a named environment should return execution info using the environment name', async () => { + test('getExecutionInfo with a named environment should return execution info using the environment path', async () => { const condaInfo = { name: 'foo', path: 'bar' }; const env = await createCondaEnv(condaInfo, processService.object, fileSystem.object); @@ -292,8 +292,8 @@ suite('CondaEnvironment', () => { expect(result).to.deep.equal({ command: condaFile, - args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args], - python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], + args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args], + python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], pythonExecutable: pythonPath, }); }); @@ -312,12 +312,12 @@ suite('CondaEnvironment', () => { }); }); - test('getExecutionObservableInfo with a named environment should return execution info using conda full path with the name', async () => { + test('getExecutionObservableInfo with a named environment should return execution info using conda full path with the path', async () => { const condaInfo = { name: 'foo', path: 'bar' }; const expected = { command: condaFile, - args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args], - python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], + args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args], + python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], pythonExecutable: pythonPath, }; const env = await createCondaEnv(condaInfo, processService.object, fileSystem.object); From 03e51eca8c570a8969843035a63c1b30d7035e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Correia?= Date: Tue, 11 Feb 2025 15:36:53 +0000 Subject: [PATCH 2/2] Include failling test --- .../common/environmentManagers/conda.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts index e621c25aeb62..9480dffe6a59 100644 --- a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts +++ b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts @@ -536,7 +536,7 @@ suite('Conda and its environments are located correctly', () => { expect(args).to.not.equal(undefined); assert.deepStrictEqual( args, - ['conda', 'run', '-n', 'envName', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], + ['conda', 'run', '-p', 'envPrefix', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], 'Incorrect args for case 1', );