2
2
// Licensed under the MIT License.
3
3
4
4
import * as path from 'path' ;
5
+ import { workspace } from 'vscode' ;
5
6
import { EXTENSION_ROOT_DIR } from '../../../constants' ;
6
7
7
8
// It is simpler to hard-code it instead of using vscode.ExtensionContext.extensionPath.
@@ -10,6 +11,22 @@ const SCRIPTS_DIR = _SCRIPTS_DIR;
10
11
export const _ISOLATED = path . join ( _SCRIPTS_DIR , 'pyvsc-run-isolated.py' ) ;
11
12
const ISOLATED = _ISOLATED ;
12
13
14
+ export function getUseIsolationSetting ( ) : boolean {
15
+ try {
16
+ return workspace . getConfiguration ( 'python' ) . get < boolean > ( 'useIsolation' , true ) ;
17
+ } catch ( ex ) {
18
+ // If we can't get the setting for any reason we assume default
19
+ return true ;
20
+ }
21
+ }
22
+
23
+ export function maybeIsolated ( args : string [ ] ) : string [ ] {
24
+ if ( getUseIsolationSetting ( ) ) {
25
+ args . splice ( 0 , 0 , ISOLATED ) ;
26
+ }
27
+ return args ;
28
+ }
29
+
13
30
// "scripts" contains everything relevant to the scripts found under
14
31
// the top-level "pythonFiles" directory. Each of those scripts has
15
32
// a function in this module which matches the script's filename.
@@ -49,7 +66,7 @@ export type InterpreterInfoJson = {
49
66
50
67
export function interpreterInfo ( ) : [ string [ ] , ( out : string ) => InterpreterInfoJson ] {
51
68
const script = path . join ( SCRIPTS_DIR , 'interpreterInfo.py' ) ;
52
- const args = [ ISOLATED , script ] ;
69
+ const args = maybeIsolated ( [ script ] ) ;
53
70
54
71
function parse ( out : string ) : InterpreterInfoJson {
55
72
let json : InterpreterInfoJson ;
@@ -159,7 +176,7 @@ namespace _completion {
159
176
160
177
export function completion ( jediPath ?: string ) : [ string [ ] , ( out : string ) => _completion . Response [ ] ] {
161
178
const script = path . join ( SCRIPTS_DIR , 'completion.py' ) ;
162
- const args = [ ISOLATED , script ] ;
179
+ const args = maybeIsolated ( [ script ] ) ;
163
180
if ( jediPath ) {
164
181
args . push ( 'custom' ) ;
165
182
args . push ( jediPath ) ;
@@ -177,7 +194,7 @@ export function completion(jediPath?: string): [string[], (out: string) => _comp
177
194
178
195
export function sortImports ( filename : string , sortArgs ?: string [ ] ) : [ string [ ] , ( out : string ) => string ] {
179
196
const script = path . join ( SCRIPTS_DIR , 'sortImports.py' ) ;
180
- const args = [ ISOLATED , script , filename , '--diff' ] ;
197
+ const args = maybeIsolated ( [ script , filename , '--diff' ] ) ;
181
198
if ( sortArgs ) {
182
199
args . push ( ...sortArgs ) ;
183
200
}
@@ -195,7 +212,7 @@ export function sortImports(filename: string, sortArgs?: string[]): [string[], (
195
212
196
213
export function refactor ( root : string ) : [ string [ ] , ( out : string ) => object [ ] ] {
197
214
const script = path . join ( SCRIPTS_DIR , 'refactor.py' ) ;
198
- const args = [ ISOLATED , script , root ] ;
215
+ const args = maybeIsolated ( [ script , root ] ) ;
199
216
200
217
// tslint:disable-next-line:no-suspicious-comment
201
218
// TODO: Make the return type more specific, like we did
@@ -217,7 +234,7 @@ export function refactor(root: string): [string[], (out: string) => object[]] {
217
234
218
235
export function normalizeForInterpreter ( ) : [ string [ ] , ( out : string ) => string ] {
219
236
const script = path . join ( SCRIPTS_DIR , 'normalizeForInterpreter.py' ) ;
220
- const args = [ ISOLATED , script ] ;
237
+ const args = maybeIsolated ( [ script ] ) ;
221
238
222
239
function parse ( out : string ) {
223
240
// The text will be used as-is.
@@ -232,7 +249,7 @@ export function normalizeForInterpreter(): [string[], (out: string) => string] {
232
249
233
250
export function normalizeSelection ( ) : [ string [ ] , ( out : string ) => string ] {
234
251
const script = path . join ( SCRIPTS_DIR , 'normalizeSelection.py' ) ;
235
- const args = [ ISOLATED , script ] ;
252
+ const args = maybeIsolated ( [ script ] ) ;
236
253
237
254
function parse ( out : string ) {
238
255
// The text will be used as-is.
@@ -272,7 +289,7 @@ export function symbolProvider(
272
289
text ?: string
273
290
) : [ string [ ] , ( out : string ) => _symbolProvider . Symbols ] {
274
291
const script = path . join ( SCRIPTS_DIR , 'symbolProvider.py' ) ;
275
- const args = [ ISOLATED , script , filename ] ;
292
+ const args = maybeIsolated ( [ script , filename ] ) ;
276
293
if ( text ) {
277
294
args . push ( text ) ;
278
295
}
@@ -289,7 +306,7 @@ export function symbolProvider(
289
306
290
307
export function printEnvVariables ( ) : [ string [ ] , ( out : string ) => NodeJS . ProcessEnv ] {
291
308
const script = path . join ( SCRIPTS_DIR , 'printEnvVariables.py' ) . fileToCommandArgument ( ) ;
292
- const args = [ ISOLATED , script ] ;
309
+ const args = maybeIsolated ( [ script ] ) ;
293
310
294
311
function parse ( out : string ) : NodeJS . ProcessEnv {
295
312
return JSON . parse ( out ) ;
@@ -303,7 +320,7 @@ export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessE
303
320
304
321
export function printEnvVariablesToFile ( filename : string ) : [ string [ ] , ( out : string ) => NodeJS . ProcessEnv ] {
305
322
const script = path . join ( SCRIPTS_DIR , 'printEnvVariablesToFile.py' ) ;
306
- const args = [ ISOLATED , script , filename . fileToCommandArgument ( ) ] ;
323
+ const args = maybeIsolated ( [ script , filename . fileToCommandArgument ( ) ] ) ;
307
324
308
325
function parse ( out : string ) : NodeJS . ProcessEnv {
309
326
return JSON . parse ( out ) ;
@@ -319,15 +336,14 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
319
336
const script = path . join ( SCRIPTS_DIR , 'shell_exec.py' ) ;
320
337
// We don't bother with a "parse" function since the output
321
338
// could be anything.
322
- return [
323
- ISOLATED ,
339
+ return maybeIsolated ( [
324
340
script ,
325
341
command . fileToCommandArgument ( ) ,
326
342
// The shell args must come after the command
327
343
// but before the lockfile.
328
344
...shellArgs ,
329
345
lockfile . fileToCommandArgument ( )
330
- ] ;
346
+ ] ) ;
331
347
}
332
348
333
349
//============================
@@ -336,7 +352,7 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
336
352
export function testlauncher ( testArgs : string [ ] ) : string [ ] {
337
353
const script = path . join ( SCRIPTS_DIR , 'testlauncher.py' ) ;
338
354
// There is no output to parse, so we do not return a function.
339
- return [ ISOLATED , script , ...testArgs ] ;
355
+ return maybeIsolated ( [ script , ...testArgs ] ) ;
340
356
}
341
357
342
358
//============================
@@ -353,5 +369,5 @@ export function visualstudio_py_testlauncher(testArgs: string[]): string[] {
353
369
354
370
export function tensorboardLauncher ( args : string [ ] ) {
355
371
const script = path . join ( SCRIPTS_DIR , 'tensorboard_launcher.py' ) ;
356
- return [ ISOLATED , script , ...args ] ;
372
+ return maybeIsolated ( [ script , ...args ] ) ;
357
373
}
0 commit comments