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
27 lines (24 loc) · 1.15 KB
/
pythonStartup.ts
File metadata and controls
27 lines (24 loc) · 1.15 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
// 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 } from '../common/vscodeApis/workspaceApis';
import { EXTENSION_ROOT_DIR } from '../constants';
export async function registerPythonStartup(context: ExtensionContext): Promise<void> {
const config = getConfiguration('python');
const pythonrcSetting = config.get<boolean>('REPL.enableShellIntegration');
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');
}
}