Skip to content

Commit 9d1fdc3

Browse files
Run all internal scripts isolated.
1 parent 3b763f0 commit 9d1fdc3

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

src/client/common/process/internal/scripts/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { PythonVersionInfo } from '../../types';
88
// It is simpler to hard-code it instead of using vscode.ExtensionContext.extensionPath.
99
export const _SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
1010
const SCRIPTS_DIR = _SCRIPTS_DIR;
11+
export const _ISOLATED = path.join(_SCRIPTS_DIR, 'pyvsc-run-isolated.py');
12+
const ISOLATED = _ISOLATED;
1113

1214
// "scripts" contains everything relevant to the scripts found under
1315
// the top-level "pythonFiles" directory. Each of those scripts has
@@ -48,7 +50,7 @@ type PythonEnvInfo = {
4850

4951
export function interpreterInfo(): [string[], (out: string) => PythonEnvInfo] {
5052
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
51-
const args = [script];
53+
const args = [ISOLATED, script];
5254

5355
function parse(out: string): PythonEnvInfo {
5456
let json: PythonEnvInfo;
@@ -158,7 +160,7 @@ namespace _completion {
158160

159161
export function completion(jediPath?: string): [string[], (out: string) => _completion.Response[]] {
160162
const script = path.join(SCRIPTS_DIR, 'completion.py');
161-
const args = [script];
163+
const args = [ISOLATED, script];
162164
if (jediPath) {
163165
args.push('custom');
164166
args.push(jediPath);
@@ -176,7 +178,7 @@ export function completion(jediPath?: string): [string[], (out: string) => _comp
176178

177179
export function sortImports(filename: string, sortArgs?: string[]): [string[], (out: string) => string] {
178180
const script = path.join(SCRIPTS_DIR, 'sortImports.py');
179-
const args = [script, filename, '--diff'];
181+
const args = [ISOLATED, script, filename, '--diff'];
180182
if (sortArgs) {
181183
args.push(...sortArgs);
182184
}
@@ -194,7 +196,7 @@ export function sortImports(filename: string, sortArgs?: string[]): [string[], (
194196

195197
export function refactor(root: string): [string[], (out: string) => object[]] {
196198
const script = path.join(SCRIPTS_DIR, 'refactor.py');
197-
const args = [script, root];
199+
const args = [ISOLATED, script, root];
198200

199201
// tslint:disable-next-line:no-suspicious-comment
200202
// TODO: Make the return type more specific, like we did
@@ -216,7 +218,7 @@ export function refactor(root: string): [string[], (out: string) => object[]] {
216218

217219
export function normalizeForInterpreter(code: string): [string[], (out: string) => string] {
218220
const script = path.join(SCRIPTS_DIR, 'normalizeForInterpreter.py');
219-
const args = [script, code];
221+
const args = [ISOLATED, script, code];
220222

221223
function parse(out: string) {
222224
// The text will be used as-is.
@@ -256,7 +258,7 @@ export function symbolProvider(
256258
text?: string
257259
): [string[], (out: string) => _symbolProvider.Symbols] {
258260
const script = path.join(SCRIPTS_DIR, 'symbolProvider.py');
259-
const args = [script, filename];
261+
const args = [ISOLATED, script, filename];
260262
if (text) {
261263
args.push(text);
262264
}
@@ -273,7 +275,7 @@ export function symbolProvider(
273275

274276
export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
275277
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgument();
276-
const args = [script];
278+
const args = [ISOLATED, script];
277279

278280
function parse(out: string): NodeJS.ProcessEnv {
279281
return JSON.parse(out);
@@ -287,7 +289,7 @@ export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessE
287289

288290
export function printEnvVariablesToFile(filename: string): [string[], (out: string) => NodeJS.ProcessEnv] {
289291
const script = path.join(SCRIPTS_DIR, 'printEnvVariablesToFile.py');
290-
const args = [script, filename.fileToCommandArgument()];
292+
const args = [ISOLATED, script, filename.fileToCommandArgument()];
291293

292294
function parse(out: string): NodeJS.ProcessEnv {
293295
return JSON.parse(out);
@@ -304,6 +306,7 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
304306
// We don't bother with a "parse" function since the output
305307
// could be anything.
306308
return [
309+
ISOLATED,
307310
script,
308311
command.fileToCommandArgument(),
309312
// The shell args must come after the command
@@ -319,7 +322,7 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
319322
export function testlauncher(testArgs: string[]): string[] {
320323
const script = path.join(SCRIPTS_DIR, 'testlauncher.py');
321324
// There is no output to parse, so we do not return a function.
322-
return [script, ...testArgs];
325+
return [ISOLATED, script, ...testArgs];
323326
}
324327

325328
//============================
@@ -328,5 +331,5 @@ export function testlauncher(testArgs: string[]): string[] {
328331
export function visualstudio_py_testlauncher(testArgs: string[]): string[] {
329332
const script = path.join(SCRIPTS_DIR, 'visualstudio_py_testlauncher.py');
330333
// There is no output to parse, so we do not return a function.
331-
return [script, ...testArgs];
334+
return [ISOLATED, script, ...testArgs];
332335
}

src/client/common/process/internal/scripts/testing_tools.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export type DiscoveredTests = {
4747

4848
export function run_adapter(adapterArgs: string[]): [string[], (out: string) => DiscoveredTests[]] {
4949
const script = path.join(SCRIPTS_DIR, 'run_adapter.py');
50+
// Note that we for now we do not run this "isolated". The
51+
// script relies on some magic that conflicts with the
52+
// isolated script.
5053
const args = [script, ...adapterArgs];
5154

5255
function parse(out: string): DiscoveredTests[] {

src/client/common/process/internal/scripts/vscode_datascience_helpers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import * as path from 'path';
5-
import { _SCRIPTS_DIR } from './index';
5+
import { _ISOLATED as ISOLATED, _SCRIPTS_DIR } from './index';
66

77
const SCRIPTS_DIR = path.join(_SCRIPTS_DIR, 'vscode_datascience_helpers');
88

@@ -12,7 +12,7 @@ const SCRIPTS_DIR = path.join(_SCRIPTS_DIR, 'vscode_datascience_helpers');
1212
export function getJupyterVariableDataFrameInfo(): string[] {
1313
const script = path.join(SCRIPTS_DIR, 'getJupyterVariableDataFrameInfo.py');
1414
// There is no script-specific output to parse, so we do not return a function.
15-
return [script];
15+
return [ISOLATED, script];
1616
}
1717

1818
//============================
@@ -21,7 +21,7 @@ export function getJupyterVariableDataFrameInfo(): string[] {
2121
export function getJupyterVariableDataFrameRows(): string[] {
2222
const script = path.join(SCRIPTS_DIR, 'getJupyterVariableDataFrameRows.py');
2323
// There is no script-specific output to parse, so we do not return a function.
24-
return [script];
24+
return [ISOLATED, script];
2525
}
2626

2727
//============================
@@ -41,7 +41,7 @@ type JupyterServerInfo = {
4141

4242
export function getServerInfo(): [string[], (out: string) => JupyterServerInfo[]] {
4343
const script = path.join(SCRIPTS_DIR, 'getServerInfo.py');
44-
const args = [script];
44+
const args = [ISOLATED, script];
4545

4646
function parse(out: string): JupyterServerInfo[] {
4747
return JSON.parse(out.trim());
@@ -56,7 +56,7 @@ export function getServerInfo(): [string[], (out: string) => JupyterServerInfo[]
5656
export function getJupyterKernels(): string[] {
5757
const script = path.join(SCRIPTS_DIR, 'getJupyterKernels.py');
5858
// There is no script-specific output to parse, so we do not return a function.
59-
return [script];
59+
return [ISOLATED, script];
6060
}
6161

6262
//============================
@@ -65,15 +65,15 @@ export function getJupyterKernels(): string[] {
6565
export function getJupyterKernelspecVersion(): string[] {
6666
const script = path.join(SCRIPTS_DIR, 'getJupyterKernelspecVersion.py');
6767
// For now we do not worry about parsing the output here.
68-
return [script];
68+
return [ISOLATED, script];
6969
}
7070

7171
//============================
7272
// jupyter_nbInstalled.py
7373

7474
export function jupyter_nbInstalled(): [string[], (out: string) => boolean] {
7575
const script = path.join(SCRIPTS_DIR, 'jupyter_nbInstalled.py');
76-
const args = [script];
76+
const args = [ISOLATED, script];
7777

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