Skip to content

Commit

Permalink
Fix invalid patch string error when using conda (#18481)
Browse files Browse the repository at this point in the history
* Fix `invalid patch string` error when using conda

* Fix tests
  • Loading branch information
karthiknadig authored Feb 8, 2022
1 parent 3b114e3 commit 41de489
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/18455.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `invalid patch string` error when using conda.
4 changes: 2 additions & 2 deletions src/client/common/process/rawProcessApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ function filterOutputUsingCondaRunMarkers(stdout: string) {
}

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

export function execObservable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class Conda {
} else {
args.push('-p', env.prefix);
}
return [this.command, 'run', ...args, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT];
return [this.command, 'run', ...args, '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT];
}

/**
Expand Down
88 changes: 80 additions & 8 deletions src/test/common/process/pythonEnvironment.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,26 @@ 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',
'-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,
});
});
Expand All @@ -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,
});
});
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
Expand Down

0 comments on commit 41de489

Please sign in to comment.