forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigSettings.ts
473 lines (438 loc) · 24.4 KB
/
configSettings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
'use strict';
import * as child_process from 'child_process';
import * as path from 'path';
import { ConfigurationChangeEvent, ConfigurationTarget, DiagnosticSeverity, Disposable, Event, EventEmitter, Uri, WorkspaceConfiguration } from 'vscode';
import '../common/extensions';
import { IInterpreterAutoSeletionProxyService } from '../interpreter/autoSelection/types';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
import { IWorkspaceService } from './application/types';
import { WorkspaceService } from './application/workspace';
import { isTestExecution } from './constants';
import { IS_WINDOWS } from './platform/constants';
import {
IAnalysisSettings,
IAutoCompleteSettings,
IDataScienceSettings,
IFormattingSettings,
ILintingSettings,
IPythonSettings,
ISortImportSettings,
ITerminalSettings,
IUnitTestSettings,
IWorkspaceSymbolSettings
} from './types';
import { debounce } from './utils/decorators';
import { SystemVariables } from './variables/systemVariables';
// tslint:disable:no-require-imports no-var-requires
const untildify = require('untildify');
// tslint:disable-next-line:completed-docs
export class PythonSettings implements IPythonSettings {
private static pythonSettings: Map<string, PythonSettings> = new Map<string, PythonSettings>();
public downloadLanguageServer = true;
public jediEnabled = true;
public jediPath = '';
public jediMemoryLimit = 1024;
public envFile = '';
public venvPath = '';
public venvFolders: string[] = [];
public condaPath = '';
public pipenvPath = '';
public devOptions: string[] = [];
public linting!: ILintingSettings;
public formatting!: IFormattingSettings;
public autoComplete!: IAutoCompleteSettings;
public unitTest!: IUnitTestSettings;
public terminal!: ITerminalSettings;
public sortImports!: ISortImportSettings;
public workspaceSymbols!: IWorkspaceSymbolSettings;
public disableInstallationChecks = false;
public globalModuleInstallation = false;
public analysis!: IAnalysisSettings;
public autoUpdateLanguageServer: boolean = true;
public datascience!: IDataScienceSettings;
protected readonly changed = new EventEmitter<void>();
private workspaceRoot: Uri;
private disposables: Disposable[] = [];
// tslint:disable-next-line:variable-name
private _pythonPath = '';
private readonly workspace: IWorkspaceService;
public get onDidChange(): Event<void> {
return this.changed.event;
}
constructor(workspaceFolder: Uri | undefined, private readonly interpreterAutoSelectionService: IInterpreterAutoSeletionProxyService,
workspace?: IWorkspaceService) {
this.workspace = workspace || new WorkspaceService();
this.workspaceRoot = workspaceFolder ? workspaceFolder : Uri.file(__dirname);
this.initialize();
}
// tslint:disable-next-line:function-name
public static getInstance(resource: Uri | undefined, interpreterAutoSelectionService: IInterpreterAutoSeletionProxyService,
workspace?: IWorkspaceService): PythonSettings {
workspace = workspace || new WorkspaceService();
const workspaceFolderUri = PythonSettings.getSettingsUriAndTarget(resource, workspace).uri;
const workspaceFolderKey = workspaceFolderUri ? workspaceFolderUri.fsPath : '';
if (!PythonSettings.pythonSettings.has(workspaceFolderKey)) {
const settings = new PythonSettings(workspaceFolderUri, interpreterAutoSelectionService, workspace);
PythonSettings.pythonSettings.set(workspaceFolderKey, settings);
// Pass null to avoid VSC from complaining about not passing in a value.
// tslint:disable-next-line:no-any
const config = workspace.getConfiguration('editor', resource ? resource : null as any);
const formatOnType = config ? config.get('formatOnType', false) : false;
sendTelemetryEvent(EventName.COMPLETION_ADD_BRACKETS, undefined, { enabled: settings.autoComplete ? settings.autoComplete.addBrackets : false });
sendTelemetryEvent(EventName.FORMAT_ON_TYPE, undefined, { enabled: formatOnType });
}
// tslint:disable-next-line:no-non-null-assertion
return PythonSettings.pythonSettings.get(workspaceFolderKey)!;
}
// tslint:disable-next-line:type-literal-delimiter
public static getSettingsUriAndTarget(resource: Uri | undefined, workspace?: IWorkspaceService): { uri: Uri | undefined, target: ConfigurationTarget } {
workspace = workspace || new WorkspaceService();
const workspaceFolder = resource ? workspace.getWorkspaceFolder(resource) : undefined;
let workspaceFolderUri: Uri | undefined = workspaceFolder ? workspaceFolder.uri : undefined;
if (!workspaceFolderUri && Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) {
workspaceFolderUri = workspace.workspaceFolders[0].uri;
}
const target = workspaceFolderUri ? ConfigurationTarget.WorkspaceFolder : ConfigurationTarget.Global;
return { uri: workspaceFolderUri, target };
}
// tslint:disable-next-line:function-name
public static dispose() {
if (!isTestExecution()) {
throw new Error('Dispose can only be called from unit tests');
}
// tslint:disable-next-line:no-void-expression
PythonSettings.pythonSettings.forEach(item => item && item.dispose());
PythonSettings.pythonSettings.clear();
}
public dispose() {
// tslint:disable-next-line:no-unsafe-any
this.disposables.forEach(disposable => disposable && disposable.dispose());
this.disposables = [];
}
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
protected update(pythonSettings: WorkspaceConfiguration) {
const workspaceRoot = this.workspaceRoot.fsPath;
const systemVariables: SystemVariables = new SystemVariables(this.workspaceRoot ? this.workspaceRoot.fsPath : undefined);
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
this.pythonPath = systemVariables.resolveAny(pythonSettings.get<string>('pythonPath'))!;
// If user has defined a custom value, use it else try to get the best interpreter ourselves.
if (this.pythonPath.length === 0 || this.pythonPath === 'python') {
const autoSelectedPythonInterpreter = this.interpreterAutoSelectionService.getAutoSelectedInterpreter(this.workspaceRoot);
if (autoSelectedPythonInterpreter) {
this.interpreterAutoSelectionService.setWorkspaceInterpreter(this.workspaceRoot, autoSelectedPythonInterpreter).ignoreErrors();
}
this.pythonPath = autoSelectedPythonInterpreter ? autoSelectedPythonInterpreter.path : this.pythonPath;
}
this.pythonPath = getAbsolutePath(this.pythonPath, workspaceRoot);
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
this.venvPath = systemVariables.resolveAny(pythonSettings.get<string>('venvPath'))!;
this.venvFolders = systemVariables.resolveAny(pythonSettings.get<string[]>('venvFolders'))!;
const condaPath = systemVariables.resolveAny(pythonSettings.get<string>('condaPath'))!;
this.condaPath = condaPath && condaPath.length > 0 ? getAbsolutePath(condaPath, workspaceRoot) : condaPath;
const pipenvPath = systemVariables.resolveAny(pythonSettings.get<string>('pipenvPath'))!;
this.pipenvPath = pipenvPath && pipenvPath.length > 0 ? getAbsolutePath(pipenvPath, workspaceRoot) : pipenvPath;
this.downloadLanguageServer = systemVariables.resolveAny(pythonSettings.get<boolean>('downloadLanguageServer', true))!;
this.jediEnabled = systemVariables.resolveAny(pythonSettings.get<boolean>('jediEnabled', true))!;
this.autoUpdateLanguageServer = systemVariables.resolveAny(pythonSettings.get<boolean>('autoUpdateLanguageServer', true))!;
if (this.jediEnabled) {
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
this.jediPath = systemVariables.resolveAny(pythonSettings.get<string>('jediPath'))!;
if (typeof this.jediPath === 'string' && this.jediPath.length > 0) {
this.jediPath = getAbsolutePath(systemVariables.resolveAny(this.jediPath), workspaceRoot);
} else {
this.jediPath = '';
}
this.jediMemoryLimit = pythonSettings.get<number>('jediMemoryLimit')!;
}
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
this.envFile = systemVariables.resolveAny(pythonSettings.get<string>('envFile'))!;
// tslint:disable-next-line:no-any
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion no-any
this.devOptions = systemVariables.resolveAny(pythonSettings.get<any[]>('devOptions'))!;
this.devOptions = Array.isArray(this.devOptions) ? this.devOptions : [];
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const lintingSettings = systemVariables.resolveAny(pythonSettings.get<ILintingSettings>('linting'))!;
if (this.linting) {
Object.assign<ILintingSettings, ILintingSettings>(this.linting, lintingSettings);
} else {
this.linting = lintingSettings;
}
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const analysisSettings = systemVariables.resolveAny(pythonSettings.get<IAnalysisSettings>('analysis'))!;
if (this.analysis) {
Object.assign<IAnalysisSettings, IAnalysisSettings>(this.analysis, analysisSettings);
} else {
this.analysis = analysisSettings;
}
this.disableInstallationChecks = pythonSettings.get<boolean>('disableInstallationCheck') === true;
this.globalModuleInstallation = pythonSettings.get<boolean>('globalModuleInstallation') === true;
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const sortImportSettings = systemVariables.resolveAny(pythonSettings.get<ISortImportSettings>('sortImports'))!;
if (this.sortImports) {
Object.assign<ISortImportSettings, ISortImportSettings>(this.sortImports, sortImportSettings);
} else {
this.sortImports = sortImportSettings;
}
// Support for travis.
this.sortImports = this.sortImports ? this.sortImports : { path: '', args: [] };
// Support for travis.
this.linting = this.linting ? this.linting : {
enabled: false,
ignorePatterns: [],
flake8Args: [], flake8Enabled: false, flake8Path: 'flake',
lintOnSave: false, maxNumberOfProblems: 100,
mypyArgs: [], mypyEnabled: false, mypyPath: 'mypy',
banditArgs: [], banditEnabled: false, banditPath: 'bandit',
pep8Args: [], pep8Enabled: false, pep8Path: 'pep8',
pylamaArgs: [], pylamaEnabled: false, pylamaPath: 'pylama',
prospectorArgs: [], prospectorEnabled: false, prospectorPath: 'prospector',
pydocstyleArgs: [], pydocstyleEnabled: false, pydocstylePath: 'pydocstyle',
pylintArgs: [], pylintEnabled: false, pylintPath: 'pylint',
pylintCategorySeverity: {
convention: DiagnosticSeverity.Hint,
error: DiagnosticSeverity.Error,
fatal: DiagnosticSeverity.Error,
refactor: DiagnosticSeverity.Hint,
warning: DiagnosticSeverity.Warning
},
pep8CategorySeverity: {
E: DiagnosticSeverity.Error,
W: DiagnosticSeverity.Warning
},
flake8CategorySeverity: {
E: DiagnosticSeverity.Error,
W: DiagnosticSeverity.Warning,
// Per http://flake8.pycqa.org/en/latest/glossary.html#term-error-code
// 'F' does not mean 'fatal as in PyLint but rather 'pyflakes' such as
// unused imports, variables, etc.
F: DiagnosticSeverity.Warning
},
mypyCategorySeverity: {
error: DiagnosticSeverity.Error,
note: DiagnosticSeverity.Hint
},
pylintUseMinimalCheckers: false
};
this.linting.pylintPath = getAbsolutePath(systemVariables.resolveAny(this.linting.pylintPath), workspaceRoot);
this.linting.flake8Path = getAbsolutePath(systemVariables.resolveAny(this.linting.flake8Path), workspaceRoot);
this.linting.pep8Path = getAbsolutePath(systemVariables.resolveAny(this.linting.pep8Path), workspaceRoot);
this.linting.pylamaPath = getAbsolutePath(systemVariables.resolveAny(this.linting.pylamaPath), workspaceRoot);
this.linting.prospectorPath = getAbsolutePath(systemVariables.resolveAny(this.linting.prospectorPath), workspaceRoot);
this.linting.pydocstylePath = getAbsolutePath(systemVariables.resolveAny(this.linting.pydocstylePath), workspaceRoot);
this.linting.mypyPath = getAbsolutePath(systemVariables.resolveAny(this.linting.mypyPath), workspaceRoot);
this.linting.banditPath = getAbsolutePath(systemVariables.resolveAny(this.linting.banditPath), workspaceRoot);
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const formattingSettings = systemVariables.resolveAny(pythonSettings.get<IFormattingSettings>('formatting'))!;
if (this.formatting) {
Object.assign<IFormattingSettings, IFormattingSettings>(this.formatting, formattingSettings);
} else {
this.formatting = formattingSettings;
}
// Support for travis.
this.formatting = this.formatting ? this.formatting : {
autopep8Args: [], autopep8Path: 'autopep8',
provider: 'autopep8',
blackArgs: [], blackPath: 'black',
yapfArgs: [], yapfPath: 'yapf'
};
this.formatting.autopep8Path = getAbsolutePath(systemVariables.resolveAny(this.formatting.autopep8Path), workspaceRoot);
this.formatting.yapfPath = getAbsolutePath(systemVariables.resolveAny(this.formatting.yapfPath), workspaceRoot);
this.formatting.blackPath = getAbsolutePath(systemVariables.resolveAny(this.formatting.blackPath), workspaceRoot);
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const autoCompleteSettings = systemVariables.resolveAny(pythonSettings.get<IAutoCompleteSettings>('autoComplete'))!;
if (this.autoComplete) {
Object.assign<IAutoCompleteSettings, IAutoCompleteSettings>(this.autoComplete, autoCompleteSettings);
} else {
this.autoComplete = autoCompleteSettings;
}
// Support for travis.
this.autoComplete = this.autoComplete ? this.autoComplete : {
extraPaths: [],
addBrackets: false,
showAdvancedMembers: false,
typeshedPaths: []
};
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const workspaceSymbolsSettings = systemVariables.resolveAny(pythonSettings.get<IWorkspaceSymbolSettings>('workspaceSymbols'))!;
if (this.workspaceSymbols) {
Object.assign<IWorkspaceSymbolSettings, IWorkspaceSymbolSettings>(this.workspaceSymbols, workspaceSymbolsSettings);
} else {
this.workspaceSymbols = workspaceSymbolsSettings;
}
// Support for travis.
this.workspaceSymbols = this.workspaceSymbols ? this.workspaceSymbols : {
ctagsPath: 'ctags',
enabled: true,
exclusionPatterns: [],
rebuildOnFileSave: true,
rebuildOnStart: true,
tagFilePath: path.join(workspaceRoot, 'tags')
};
this.workspaceSymbols.tagFilePath = getAbsolutePath(systemVariables.resolveAny(this.workspaceSymbols.tagFilePath), workspaceRoot);
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const unitTestSettings = systemVariables.resolveAny(pythonSettings.get<IUnitTestSettings>('unitTest'))!;
if (this.unitTest) {
Object.assign<IUnitTestSettings, IUnitTestSettings>(this.unitTest, unitTestSettings);
} else {
this.unitTest = unitTestSettings;
if (isTestExecution() && !this.unitTest) {
// tslint:disable-next-line:prefer-type-cast
// tslint:disable-next-line:no-object-literal-type-assertion
this.unitTest = {
nosetestArgs: [], pyTestArgs: [], unittestArgs: [],
promptToConfigure: true, debugPort: 3000,
nosetestsEnabled: false, pyTestEnabled: false, unittestEnabled: false,
nosetestPath: 'nosetests', pyTestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true
} as IUnitTestSettings;
}
}
// Support for travis.
this.unitTest = this.unitTest ? this.unitTest : {
promptToConfigure: true,
debugPort: 3000,
nosetestArgs: [], nosetestPath: 'nosetest', nosetestsEnabled: false,
pyTestArgs: [], pyTestEnabled: false, pyTestPath: 'pytest',
unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true
};
this.unitTest.pyTestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.pyTestPath), workspaceRoot);
this.unitTest.nosetestPath = getAbsolutePath(systemVariables.resolveAny(this.unitTest.nosetestPath), workspaceRoot);
if (this.unitTest.cwd) {
this.unitTest.cwd = getAbsolutePath(systemVariables.resolveAny(this.unitTest.cwd), workspaceRoot);
}
// Resolve any variables found in the test arguments.
this.unitTest.nosetestArgs = this.unitTest.nosetestArgs.map(arg => systemVariables.resolveAny(arg));
this.unitTest.pyTestArgs = this.unitTest.pyTestArgs.map(arg => systemVariables.resolveAny(arg));
this.unitTest.unittestArgs = this.unitTest.unittestArgs.map(arg => systemVariables.resolveAny(arg));
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
const terminalSettings = systemVariables.resolveAny(pythonSettings.get<ITerminalSettings>('terminal'))!;
if (this.terminal) {
Object.assign<ITerminalSettings, ITerminalSettings>(this.terminal, terminalSettings);
} else {
this.terminal = terminalSettings;
if (isTestExecution() && !this.terminal) {
// tslint:disable-next-line:prefer-type-cast
// tslint:disable-next-line:no-object-literal-type-assertion
this.terminal = {} as ITerminalSettings;
}
}
// Support for travis.
this.terminal = this.terminal ? this.terminal : {
executeInFileDir: true,
launchArgs: [],
activateEnvironment: true
};
const dataScienceSettings = systemVariables.resolveAny(pythonSettings.get<IDataScienceSettings>('dataScience'))!;
if (this.datascience) {
Object.assign<IDataScienceSettings, IDataScienceSettings>(this.datascience, dataScienceSettings);
} else {
this.datascience = dataScienceSettings;
}
}
public get pythonPath(): string {
return this._pythonPath;
}
public set pythonPath(value: string) {
if (this._pythonPath === value) {
return;
}
// Add support for specifying just the directory where the python executable will be located.
// E.g. virtual directory name.
try {
this._pythonPath = this.getPythonExecutable(value);
} catch (ex) {
this._pythonPath = value;
}
}
protected getPythonExecutable(pythonPath: string) {
return getPythonExecutable(pythonPath);
}
protected onWorkspaceFoldersChanged() {
//If an activated workspace folder was removed, delete its key
const workspaceKeys = this.workspace.workspaceFolders!.map(workspaceFolder => workspaceFolder.uri.fsPath);
const activatedWkspcKeys = Array.from(PythonSettings.pythonSettings.keys());
const activatedWkspcFoldersRemoved = activatedWkspcKeys.filter(item => workspaceKeys.indexOf(item) < 0);
if (activatedWkspcFoldersRemoved.length > 0) {
for (const folder of activatedWkspcFoldersRemoved) {
PythonSettings.pythonSettings.delete(folder);
}
}
}
protected initialize(): void {
const onDidChange = () => {
const currentConfig = this.workspace.getConfiguration('python', this.workspaceRoot);
this.update(currentConfig);
// If workspace config changes, then we could have a cascading effect of on change events.
// Let's defer the change notification.
this.debounceChangeNotification();
};
this.disposables.push(this.workspace.onDidChangeWorkspaceFolders(this.onWorkspaceFoldersChanged, this));
this.disposables.push(this.interpreterAutoSelectionService.onDidChangeAutoSelectedInterpreter(onDidChange.bind(this)));
this.disposables.push(this.workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration('python')) {
onDidChange();
}
}));
const initialConfig = this.workspace.getConfiguration('python', this.workspaceRoot);
if (initialConfig) {
this.update(initialConfig);
}
}
@debounce(1)
protected debounceChangeNotification() {
this.changed.fire();
}
}
function getAbsolutePath(pathToCheck: string, rootDir: string): string {
// tslint:disable-next-line:prefer-type-cast no-unsafe-any
pathToCheck = untildify(pathToCheck) as string;
if (isTestExecution() && !pathToCheck) { return rootDir; }
if (pathToCheck.indexOf(path.sep) === -1) {
return pathToCheck;
}
return path.isAbsolute(pathToCheck) ? pathToCheck : path.resolve(rootDir, pathToCheck);
}
function getPythonExecutable(pythonPath: string): string {
// tslint:disable-next-line:prefer-type-cast no-unsafe-any
pythonPath = untildify(pythonPath) as string;
// If only 'python'.
if (pythonPath === 'python' ||
pythonPath.indexOf(path.sep) === -1 ||
path.basename(pythonPath) === path.dirname(pythonPath)) {
return pythonPath;
}
if (isValidPythonPath(pythonPath)) {
return pythonPath;
}
// Keep python right on top, for backwards compatibility.
// tslint:disable-next-line:variable-name
const KnownPythonExecutables = ['python', 'python4', 'python3.6', 'python3.5', 'python3', 'python2.7', 'python2'];
for (let executableName of KnownPythonExecutables) {
// Suffix with 'python' for linux and 'osx', and 'python.exe' for 'windows'.
if (IS_WINDOWS) {
executableName = `${executableName}.exe`;
if (isValidPythonPath(path.join(pythonPath, executableName))) {
return path.join(pythonPath, executableName);
}
if (isValidPythonPath(path.join(pythonPath, 'scripts', executableName))) {
return path.join(pythonPath, 'scripts', executableName);
}
} else {
if (isValidPythonPath(path.join(pythonPath, executableName))) {
return path.join(pythonPath, executableName);
}
if (isValidPythonPath(path.join(pythonPath, 'bin', executableName))) {
return path.join(pythonPath, 'bin', executableName);
}
}
}
return pythonPath;
}
function isValidPythonPath(pythonPath: string): boolean {
try {
const output = child_process.execFileSync(pythonPath, ['-c', 'print(1234)'], { encoding: 'utf8' });
return output.startsWith('1234');
} catch (ex) {
return false;
}
}