Skip to content

Commit 41de489

Browse files
authored
Fix invalid patch string error when using conda (#18481)
* Fix `invalid patch string` error when using conda * Fix tests
1 parent 3b114e3 commit 41de489

File tree

5 files changed

+86
-13
lines changed

5 files changed

+86
-13
lines changed

news/2 Fixes/18455.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `invalid patch string` error when using conda.

src/client/common/process/rawProcessApis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ function filterOutputUsingCondaRunMarkers(stdout: string) {
169169
}
170170

171171
function removeCondaRunMarkers(out: string) {
172-
out = out.replace('>>>PYTHON-EXEC-OUTPUT', '');
173-
return out.replace('<<<PYTHON-EXEC-OUTPUT', '');
172+
out = out.replace('>>>PYTHON-EXEC-OUTPUT\r\n', '').replace('>>>PYTHON-EXEC-OUTPUT\n', '');
173+
return out.replace('<<<PYTHON-EXEC-OUTPUT\r\n', '').replace('<<<PYTHON-EXEC-OUTPUT\n', '');
174174
}
175175

176176
export function execObservable(

src/client/pythonEnvironments/common/environmentManagers/conda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class Conda {
416416
} else {
417417
args.push('-p', env.prefix);
418418
}
419-
return [this.command, 'run', ...args, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT];
419+
return [this.command, 'run', ...args, '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT];
420420
}
421421

422422
/**

src/test/common/process/pythonEnvironment.unit.test.ts

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,26 @@ suite('CondaEnvironment', () => {
291291

292292
expect(result).to.deep.equal({
293293
command: condaFile,
294-
args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
295-
python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
294+
args: [
295+
'run',
296+
'-n',
297+
condaInfo.name,
298+
'--no-capture-output',
299+
'--live-stream',
300+
'python',
301+
OUTPUT_MARKER_SCRIPT,
302+
...args,
303+
],
304+
python: [
305+
condaFile,
306+
'run',
307+
'-n',
308+
condaInfo.name,
309+
'--no-capture-output',
310+
'--live-stream',
311+
'python',
312+
OUTPUT_MARKER_SCRIPT,
313+
],
296314
pythonExecutable: pythonPath,
297315
});
298316
});
@@ -305,8 +323,26 @@ suite('CondaEnvironment', () => {
305323

306324
expect(result).to.deep.equal({
307325
command: condaFile,
308-
args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
309-
python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
326+
args: [
327+
'run',
328+
'-p',
329+
condaInfo.path,
330+
'--no-capture-output',
331+
'--live-stream',
332+
'python',
333+
OUTPUT_MARKER_SCRIPT,
334+
...args,
335+
],
336+
python: [
337+
condaFile,
338+
'run',
339+
'-p',
340+
condaInfo.path,
341+
'--no-capture-output',
342+
'--live-stream',
343+
'python',
344+
OUTPUT_MARKER_SCRIPT,
345+
],
310346
pythonExecutable: pythonPath,
311347
});
312348
});
@@ -315,8 +351,26 @@ suite('CondaEnvironment', () => {
315351
const condaInfo = { name: 'foo', path: 'bar' };
316352
const expected = {
317353
command: condaFile,
318-
args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
319-
python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
354+
args: [
355+
'run',
356+
'-n',
357+
condaInfo.name,
358+
'--no-capture-output',
359+
'--live-stream',
360+
'python',
361+
OUTPUT_MARKER_SCRIPT,
362+
...args,
363+
],
364+
python: [
365+
condaFile,
366+
'run',
367+
'-n',
368+
condaInfo.name,
369+
'--no-capture-output',
370+
'--live-stream',
371+
'python',
372+
OUTPUT_MARKER_SCRIPT,
373+
],
320374
pythonExecutable: pythonPath,
321375
};
322376
const env = await createCondaEnv(condaInfo, pythonPath, processService.object, fileSystem.object);
@@ -330,8 +384,26 @@ suite('CondaEnvironment', () => {
330384
const condaInfo = { name: '', path: 'bar' };
331385
const expected = {
332386
command: condaFile,
333-
args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
334-
python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
387+
args: [
388+
'run',
389+
'-p',
390+
condaInfo.path,
391+
'--no-capture-output',
392+
'--live-stream',
393+
'python',
394+
OUTPUT_MARKER_SCRIPT,
395+
...args,
396+
],
397+
python: [
398+
condaFile,
399+
'run',
400+
'-p',
401+
condaInfo.path,
402+
'--no-capture-output',
403+
'--live-stream',
404+
'python',
405+
OUTPUT_MARKER_SCRIPT,
406+
],
335407
pythonExecutable: pythonPath,
336408
};
337409
const env = await createCondaEnv(condaInfo, pythonPath, processService.object, fileSystem.object);

src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,14 @@ suite('Conda and its environments are located correctly', () => {
481481
expect(args).to.not.equal(undefined);
482482
assert.deepStrictEqual(
483483
args,
484-
['conda', 'run', '-n', 'envName', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
484+
['conda', 'run', '-n', 'envName', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT],
485485
'Incorrect args for case 1',
486486
);
487487

488488
args = await conda?.getRunPythonArgs({ name: '', prefix: 'envPrefix' });
489489
assert.deepStrictEqual(
490490
args,
491-
['conda', 'run', '-p', 'envPrefix', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
491+
['conda', 'run', '-p', 'envPrefix', '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT],
492492
'Incorrect args for case 2',
493493
);
494494
});

0 commit comments

Comments
 (0)