forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.ts
More file actions
59 lines (50 loc) · 2.22 KB
/
Copy pathinitialize.ts
File metadata and controls
59 lines (50 loc) · 2.22 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// tslint:disable:no-string-literal
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { PythonSettings } from '../client/common/configSettings';
import { activated } from '../client/extension';
import { clearPythonPathInWorkspaceFolder, resetGlobalPythonPathSetting, setPythonPathInWorkspaceRoot } from './common';
export * from './constants';
const dummyPythonFile = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'dummy.py');
const multirootPath = path.join(__dirname, '..', '..', 'src', 'testMultiRootWkspc');
const workspace3Uri = vscode.Uri.file(path.join(multirootPath, 'workspace3'));
//First thing to be executed.
process.env['VSC_PYTHON_CI_TEST'] = '1';
const PYTHON_PATH = getPythonPath();
// Ability to use custom python environments for testing
export async function initializePython() {
await resetGlobalPythonPathSetting();
await clearPythonPathInWorkspaceFolder(dummyPythonFile);
await clearPythonPathInWorkspaceFolder(workspace3Uri);
await setPythonPathInWorkspaceRoot(PYTHON_PATH);
}
// tslint:disable-next-line:no-any
export async function initialize(): Promise<any> {
await initializePython();
// Opening a python file activates the extension.
await vscode.workspace.openTextDocument(dummyPythonFile);
await activated;
// Dispose any cached python settings (used only in test env).
PythonSettings.dispose();
}
// tslint:disable-next-line:no-any
export async function initializeTest(): Promise<any> {
await initializePython();
await closeActiveWindows();
// Dispose any cached python settings (used only in test env).
PythonSettings.dispose();
}
export async function closeActiveWindows(): Promise<void> {
return new Promise<void>((resolve, reject) => vscode.commands.executeCommand('workbench.action.closeAllEditors')
// tslint:disable-next-line:no-unnecessary-callback-wrapper
.then(() => resolve(), reject));
}
function getPythonPath(): string {
// tslint:disable-next-line:no-unsafe-any
if (process.env.TRAVIS_PYTHON_PATH && fs.existsSync(process.env.TRAVIS_PYTHON_PATH)) {
// tslint:disable-next-line:no-unsafe-any
return process.env.TRAVIS_PYTHON_PATH;
}
return 'python';
}