Skip to content

Commit d8a6cf3

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

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/client/common/process/internal.ts

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

8+
// It is simpler to hard-code the extension root dir than to use vscode.ExtensionContext.extensionPath.
9+
const SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
10+
const ISOLATED = path.join(SCRIPTS_DIR, 'pyvsc-run-isolated.py');
11+
812
/****************************
913
* The following namespaces cover the following:
1014
*
@@ -40,9 +44,6 @@ import { PythonVersionInfo } from './types';
4044
// * install_debugpy.py (used only for extension development)
4145
// * ptvsd_launcher.py (used only for the old debug adapter)
4246
export namespace scripts {
43-
// It is simpler to hard-code it instead of using vscode.ExtensionContext.extensionPath.
44-
const SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
45-
4647
//============================
4748
// interpreterInfo.py
4849

@@ -55,7 +56,7 @@ export namespace scripts {
5556

5657
export function interpreterInfo(): [string[], (out: string) => PythonEnvInfo] {
5758
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
58-
const args = [script];
59+
const args = [ISOLATED, script];
5960

6061
function parse(out: string): PythonEnvInfo {
6162
let json: PythonEnvInfo;
@@ -165,7 +166,7 @@ export namespace scripts {
165166

166167
export function completion(jediPath?: string): [string[], (out: string) => _completion.Response[]] {
167168
const script = path.join(SCRIPTS_DIR, 'completion.py');
168-
const args = [script];
169+
const args = [ISOLATED, script];
169170
if (jediPath) {
170171
args.push('custom');
171172
args.push(jediPath);
@@ -183,7 +184,7 @@ export namespace scripts {
183184

184185
export function sortImports(filename: string, sortArgs?: string[]): [string[], (out: string) => string] {
185186
const script = path.join(SCRIPTS_DIR, 'sortImports.py');
186-
const args = [script, filename, '--diff'];
187+
const args = [ISOLATED, script, filename, '--diff'];
187188
if (sortArgs) {
188189
args.push(...sortArgs);
189190
}
@@ -201,7 +202,7 @@ export namespace scripts {
201202

202203
export function refactor(root: string): [string[], (out: string) => object[]] {
203204
const script = path.join(SCRIPTS_DIR, 'refactor.py');
204-
const args = [script, root];
205+
const args = [ISOLATED, script, root];
205206

206207
// tslint:disable-next-line:no-suspicious-comment
207208
// TODO: Make the return type more specific, like we did
@@ -223,7 +224,7 @@ export namespace scripts {
223224

224225
export function normalizeForInterpreter(code: string): [string[], (out: string) => string] {
225226
const script = path.join(SCRIPTS_DIR, 'normalizeForInterpreter.py');
226-
const args = [script, code];
227+
const args = [ISOLATED, script, code];
227228

228229
function parse(out: string) {
229230
// The text will be used as-is.
@@ -262,7 +263,7 @@ export namespace scripts {
262263
text?: string
263264
): [string[], (out: string) => _symbolProvider.Symbols] {
264265
const script = path.join(SCRIPTS_DIR, 'symbolProvider.py');
265-
const args = [script, filename];
266+
const args = [ISOLATED, script, filename];
266267
if (text) {
267268
args.push(text);
268269
}
@@ -279,7 +280,7 @@ export namespace scripts {
279280

280281
export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
281282
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgument();
282-
const args = [script];
283+
const args = [ISOLATED, script];
283284

284285
function parse(out: string): NodeJS.ProcessEnv {
285286
return JSON.parse(out);
@@ -293,7 +294,7 @@ export namespace scripts {
293294

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

298299
function parse(out: string): NodeJS.ProcessEnv {
299300
return JSON.parse(out);
@@ -310,6 +311,7 @@ export namespace scripts {
310311
// We don't bother with a "parse" function since the output
311312
// could be anything.
312313
return [
314+
ISOLATED,
313315
script,
314316
command.fileToCommandArgument(),
315317
// The shell args must come after the command
@@ -325,7 +327,7 @@ export namespace scripts {
325327
export function testlauncher(testArgs: string[]): string[] {
326328
const script = path.join(SCRIPTS_DIR, 'testlauncher.py');
327329
// There is no output to parse, so we do not return a function.
328-
return [script, ...testArgs];
330+
return [ISOLATED, script, ...testArgs];
329331
}
330332

331333
//============================
@@ -334,7 +336,7 @@ export namespace scripts {
334336
export function visualstudio_py_testlauncher(testArgs: string[]): string[] {
335337
const script = path.join(SCRIPTS_DIR, 'visualstudio_py_testlauncher.py');
336338
// There is no output to parse, so we do not return a function.
337-
return [script, ...testArgs];
339+
return [ISOLATED, script, ...testArgs];
338340
}
339341

340342
//============================
@@ -384,6 +386,9 @@ export namespace scripts {
384386

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

389394
function parse(out: string): DiscoveredTests[] {
@@ -418,7 +423,7 @@ export namespace scripts {
418423
export function getJupyterVariableDataFrameInfo(): string[] {
419424
const script = path.join(_SCRIPTS_DIR, 'getJupyterVariableDataFrameInfo.py');
420425
// There is no script-specific output to parse, so we do not return a function.
421-
return [script];
426+
return [ISOLATED, script];
422427
}
423428

424429
//============================
@@ -427,15 +432,15 @@ export namespace scripts {
427432
export function getJupyterVariableDataFrameRows(): string[] {
428433
const script = path.join(_SCRIPTS_DIR, 'getJupyterVariableDataFrameRows.py');
429434
// There is no script-specific output to parse, so we do not return a function.
430-
return [script];
435+
return [ISOLATED, script];
431436
}
432437

433438
//============================
434439
// getServerInfo.py
435440

436441
export function getServerInfo(): [string[], (out: string) => JupyterServerInfo[]] {
437442
const script = path.join(_SCRIPTS_DIR, 'getServerInfo.py');
438-
const args = [script];
443+
const args = [ISOLATED, script];
439444

440445
function parse(out: string): JupyterServerInfo[] {
441446
return JSON.parse(out.trim());
@@ -450,7 +455,7 @@ export namespace scripts {
450455
export function getJupyterKernels(): string[] {
451456
const script = path.join(_SCRIPTS_DIR, 'getJupyterKernels.py');
452457
// There is no script-specific output to parse, so we do not return a function.
453-
return [script];
458+
return [ISOLATED, script];
454459
}
455460

456461
//============================
@@ -459,15 +464,15 @@ export namespace scripts {
459464
export function getJupyterKernelspecVersion(): string[] {
460465
const script = path.join(_SCRIPTS_DIR, 'getJupyterKernelspecVersion.py');
461466
// For now we do not worry about parsing the output here.
462-
return [script];
467+
return [ISOLATED, script];
463468
}
464469

465470
//============================
466471
// jupyter_nbInstalled.py
467472

468473
export function jupyter_nbInstalled(): [string[], (out: string) => boolean] {
469474
const script = path.join(_SCRIPTS_DIR, 'jupyter_nbInstalled.py');
470-
const args = [script];
475+
const args = [ISOLATED, script];
471476

472477
function parse(out: string): boolean {
473478
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)