forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpythonStartup.ts
More file actions
38 lines (34 loc) · 1.57 KB
/
pythonStartup.ts
File metadata and controls
38 lines (34 loc) · 1.57 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { ExtensionContext, Uri } from 'vscode';
import * as path from 'path';
import { copy, createDirectory, getConfiguration, onDidChangeConfiguration } from '../common/vscodeApis/workspaceApis';
import { EXTENSION_ROOT_DIR } from '../constants';
async function applyPythonStartupSetting(context: ExtensionContext): Promise<void> {
const config = getConfiguration('python');
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
if (pythonrcSetting) {
const storageUri = context.storageUri || context.globalStorageUri;
try {
await createDirectory(storageUri);
} catch {
// already exists, most likely
}
const destPath = Uri.joinPath(storageUri, 'pythonrc.py');
const sourcePath = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py');
await copy(Uri.file(sourcePath), destPath, { overwrite: true });
context.environmentVariableCollection.replace('PYTHONSTARTUP', destPath.fsPath);
} else {
context.environmentVariableCollection.delete('PYTHONSTARTUP');
}
}
export async function registerPythonStartup(context: ExtensionContext): Promise<void> {
await applyPythonStartupSetting(context);
context.subscriptions.push(
onDidChangeConfiguration(async (e) => {
if (e.affectsConfiguration('python.terminal.shellIntegration.enabled')) {
await applyPythonStartupSetting(context);
}
}),
);
}