From 41de48900783b0d948019fe5a6e3fd1f5ceb2a3b Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 8 Feb 2022 12:07:24 -0800 Subject: [PATCH] Fix `invalid patch string` error when using conda (#18481) * Fix `invalid patch string` error when using conda * Fix tests --- news/2 Fixes/18455.md | 1 + src/client/common/process/rawProcessApis.ts | 4 +- .../common/environmentManagers/conda.ts | 2 +- .../process/pythonEnvironment.unit.test.ts | 88 +++++++++++++++++-- .../environmentManagers/conda.unit.test.ts | 4 +- 5 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 news/2 Fixes/18455.md diff --git a/news/2 Fixes/18455.md b/news/2 Fixes/18455.md new file mode 100644 index 000000000000..a2df2f11c124 --- /dev/null +++ b/news/2 Fixes/18455.md @@ -0,0 +1 @@ +Fix `invalid patch string` error when using conda. diff --git a/src/client/common/process/rawProcessApis.ts b/src/client/common/process/rawProcessApis.ts index 096d79a73db5..b07c640c2e95 100644 --- a/src/client/common/process/rawProcessApis.ts +++ b/src/client/common/process/rawProcessApis.ts @@ -169,8 +169,8 @@ function filterOutputUsingCondaRunMarkers(stdout: string) { } function removeCondaRunMarkers(out: string) { - out = out.replace('>>>PYTHON-EXEC-OUTPUT', ''); - return out.replace('<<>>PYTHON-EXEC-OUTPUT\r\n', '').replace('>>>PYTHON-EXEC-OUTPUT\n', ''); + return out.replace('<< { 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', + '-n', + condaInfo.name, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ...args, + ], + python: [ + condaFile, + 'run', + '-n', + condaInfo.name, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ], pythonExecutable: pythonPath, }); }); @@ -305,8 +323,26 @@ suite('CondaEnvironment', () => { expect(result).to.deep.equal({ command: condaFile, - 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], + args: [ + 'run', + '-p', + condaInfo.path, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ...args, + ], + python: [ + condaFile, + 'run', + '-p', + condaInfo.path, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ], pythonExecutable: pythonPath, }); }); @@ -315,8 +351,26 @@ suite('CondaEnvironment', () => { 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', + '-n', + condaInfo.name, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ...args, + ], + python: [ + condaFile, + 'run', + '-n', + condaInfo.name, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ], pythonExecutable: pythonPath, }; const env = await createCondaEnv(condaInfo, pythonPath, processService.object, fileSystem.object); @@ -330,8 +384,26 @@ suite('CondaEnvironment', () => { const condaInfo = { name: '', path: 'bar' }; const expected = { command: condaFile, - 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], + args: [ + 'run', + '-p', + condaInfo.path, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ...args, + ], + python: [ + condaFile, + 'run', + '-p', + condaInfo.path, + '--no-capture-output', + '--live-stream', + 'python', + OUTPUT_MARKER_SCRIPT, + ], pythonExecutable: pythonPath, }; const env = await createCondaEnv(condaInfo, pythonPath, processService.object, fileSystem.object); diff --git a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts index cdfd3284891d..c6d068eabc6e 100644 --- a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts +++ b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts @@ -481,14 +481,14 @@ 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', '-n', 'envName', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT], 'Incorrect args for case 1', ); args = await conda?.getRunPythonArgs({ name: '', prefix: 'envPrefix' }); assert.deepStrictEqual( args, - ['conda', 'run', '-p', 'envPrefix', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT], + ['conda', 'run', '-p', 'envPrefix', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT], 'Incorrect args for case 2', ); });