Skip to content

Commit 936cb2d

Browse files
Run all internal scripts isolated.
1 parent a707a35 commit 936cb2d

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/client/common/process/internal.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as path from 'path';
55
import { EXTENSION_ROOT_DIR } from '../constants';
66
import { PythonVersionInfo } from './types';
77

8+
const ISOLATED = path.join(SCRIPTS_DIR, 'pyvsc-run-isolated.py');
9+
810
/****************************
911
* The following namespaces cover the following:
1012
*
@@ -55,7 +57,7 @@ export namespace scripts {
5557

5658
export function interpreterInfo(): [string[], (out: string) => PythonEnvInfo] {
5759
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
58-
const args = [script];
60+
const args = [ISOLATED, script];
5961

6062
function parse(out: string): PythonEnvInfo {
6163
let json: PythonEnvInfo;
@@ -165,7 +167,7 @@ export namespace scripts {
165167

166168
export function completion(jediPath?: string): [string[], (out: string) => _completion.Response[]] {
167169
const script = path.join(SCRIPTS_DIR, 'completion.py');
168-
const args = [script];
170+
const args = [ISOLATED, script];
169171
if (jediPath) {
170172
args.push('custom');
171173
args.push(jediPath);
@@ -183,7 +185,7 @@ export namespace scripts {
183185

184186
export function sortImports(filename: string, sortArgs?: string[]): [string[], (out: string) => string] {
185187
const script = path.join(SCRIPTS_DIR, 'sortImports.py');
186-
const args = [script, filename, '--diff'];
188+
const args = [ISOLATED, script, filename, '--diff'];
187189
if (sortArgs) {
188190
args.push(...sortArgs);
189191
}
@@ -201,7 +203,7 @@ export namespace scripts {
201203

202204
export function refactor(root: string): [string[], (out: string) => object[]] {
203205
const script = path.join(SCRIPTS_DIR, 'refactor.py');
204-
const args = [script, root];
206+
const args = [ISOLATED, script, root];
205207

206208
// tslint:disable-next-line:no-suspicious-comment
207209
// TODO: Make the return type more specific, like we did
@@ -223,7 +225,7 @@ export namespace scripts {
223225

224226
export function normalizeForInterpreter(code: string): [string[], (out: string) => string] {
225227
const script = path.join(SCRIPTS_DIR, 'normalizeForInterpreter.py');
226-
const args = [script, code];
228+
const args = [ISOLATED, script, code];
227229

228230
function parse(out: string) {
229231
// The text will be used as-is.
@@ -262,7 +264,7 @@ export namespace scripts {
262264
text?: string
263265
): [string[], (out: string) => _symbolProvider.Symbols] {
264266
const script = path.join(SCRIPTS_DIR, 'symbolProvider.py');
265-
const args = [script, filename];
267+
const args = [ISOLATED, script, filename];
266268
if (text) {
267269
args.push(text);
268270
}
@@ -279,7 +281,7 @@ export namespace scripts {
279281

280282
export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
281283
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgument();
282-
const args = [script];
284+
const args = [ISOLATED, script];
283285

284286
function parse(out: string): NodeJS.ProcessEnv {
285287
return JSON.parse(out);
@@ -293,7 +295,7 @@ export namespace scripts {
293295

294296
export function printEnvVariablesToFile(filename: string): [string[], (out: string) => NodeJS.ProcessEnv] {
295297
const script = path.join(SCRIPTS_DIR, 'printEnvVariablesToFile.py');
296-
const args = [script, filename.fileToCommandArgument()];
298+
const args = [ISOLATED, script, filename.fileToCommandArgument()];
297299

298300
function parse(out: string): NodeJS.ProcessEnv {
299301
return JSON.parse(out);
@@ -310,6 +312,7 @@ export namespace scripts {
310312
// We don't bother with a "parse" function since the output
311313
// could be anything.
312314
return [
315+
ISOLATED,
313316
script,
314317
command.fileToCommandArgument(),
315318
// The shell args must come after the command
@@ -325,7 +328,7 @@ export namespace scripts {
325328
export function testlauncher(testArgs: string[]): string[] {
326329
const script = path.join(SCRIPTS_DIR, 'testlauncher.py');
327330
// There is no output to parse, so we do not return a function.
328-
return [script, ...testArgs];
331+
return [ISOLATED, script, ...testArgs];
329332
}
330333

331334
//============================
@@ -334,7 +337,7 @@ export namespace scripts {
334337
export function visualstudio_py_testlauncher(testArgs: string[]): string[] {
335338
const script = path.join(SCRIPTS_DIR, 'visualstudio_py_testlauncher.py');
336339
// There is no output to parse, so we do not return a function.
337-
return [script, ...testArgs];
340+
return [ISOLATED, script, ...testArgs];
338341
}
339342

340343
//============================
@@ -384,6 +387,9 @@ export namespace scripts {
384387

385388
export function run_adapter(adapterArgs: string[]): [string[], (out: string) => DiscoveredTests[]] {
386389
const script = path.join(_SCRIPTS_DIR, 'run_adapter.py');
390+
// Note that we for now we do not run this "isolated". The
391+
// script relies on some magic that conflicts with the
392+
// isolated script.
387393
const args = [script, ...adapterArgs];
388394

389395
function parse(out: string): DiscoveredTests[] {
@@ -418,7 +424,7 @@ export namespace scripts {
418424
export function getJupyterVariableDataFrameInfo(): string[] {
419425
const script = path.join(_SCRIPTS_DIR, 'getJupyterVariableDataFrameInfo.py');
420426
// There is no script-specific output to parse, so we do not return a function.
421-
return [script];
427+
return [ISOLATED, script];
422428
}
423429

424430
//============================
@@ -427,15 +433,15 @@ export namespace scripts {
427433
export function getJupyterVariableDataFrameRows(): string[] {
428434
const script = path.join(_SCRIPTS_DIR, 'getJupyterVariableDataFrameRows.py');
429435
// There is no script-specific output to parse, so we do not return a function.
430-
return [script];
436+
return [ISOLATED, script];
431437
}
432438

433439
//============================
434440
// getServerInfo.py
435441

436442
export function getServerInfo(): [string[], (out: string) => JupyterServerInfo[]] {
437443
const script = path.join(_SCRIPTS_DIR, 'getServerInfo.py');
438-
const args = [script];
444+
const args = [ISOLATED, script];
439445

440446
function parse(out: string): JupyterServerInfo[] {
441447
return JSON.parse(out.trim());
@@ -450,7 +456,7 @@ export namespace scripts {
450456
export function getJupyterKernels(): string[] {
451457
const script = path.join(_SCRIPTS_DIR, 'getJupyterKernels.py');
452458
// There is no script-specific output to parse, so we do not return a function.
453-
return [script];
459+
return [ISOLATED, script];
454460
}
455461

456462
//============================
@@ -459,15 +465,15 @@ export namespace scripts {
459465
export function getJupyterKernelspecVersion(): string[] {
460466
const script = path.join(_SCRIPTS_DIR, 'getJupyterKernelspecVersion.py');
461467
// For now we do not worry about parsing the output here.
462-
return [script];
468+
return [ISOLATED, script];
463469
}
464470

465471
//============================
466472
// jupyter_nbInstalled.py
467473

468474
export function jupyter_nbInstalled(): [string[], (out: string) => boolean] {
469475
const script = path.join(_SCRIPTS_DIR, 'jupyter_nbInstalled.py');
470-
const args = [script];
476+
const args = [ISOLATED, script];
471477

472478
function parse(out: string): boolean {
473479
return out.toLowerCase().includes('available');

src/test/providers/importSortProvider.unit.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { IServiceContainer } from '../../client/ioc/types';
3131
import { SortImportsEditingProvider } from '../../client/providers/importSortProvider';
3232
import { ISortImportsEditingProvider } from '../../client/providers/types';
3333

34+
const ISOLATED = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'pyvsc-run-isolated.py');
35+
3436
suite('Import Sort Provider', () => {
3537
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
3638
let shell: TypeMoq.IMock<IApplicationShell>;
@@ -398,7 +400,7 @@ suite('Import Sort Provider', () => {
398400
.returns(() => Promise.resolve(processExeService.object))
399401
.verifiable(TypeMoq.Times.once());
400402
const importScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'sortImports.py');
401-
const expectedArgs = [importScript, tmpFile.filePath, '--diff', '1', '2'];
403+
const expectedArgs = [ISOLATED, importScript, tmpFile.filePath, '--diff', '1', '2'];
402404
processExeService
403405
.setup((p) =>
404406
p.exec(TypeMoq.It.isValue(expectedArgs), TypeMoq.It.isValue({ throwOnStdErr: true, token: undefined }))

0 commit comments

Comments
 (0)