forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommonUtils.ts
More file actions
42 lines (36 loc) · 1.78 KB
/
commonUtils.ts
File metadata and controls
42 lines (36 loc) · 1.78 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { WorkspaceFolder } from 'vscode';
import * as fs from '../../../common/platform/fs-paths';
import { Commands } from '../../../common/constants';
import { Common } from '../../../common/utils/localize';
import { executeCommand } from '../../../common/vscodeApis/commandApis';
import { showErrorMessage } from '../../../common/vscodeApis/windowApis';
import { isWindows } from '../../../common/utils/platform';
export async function showErrorMessageWithLogs(message: string): Promise<void> {
const result = await showErrorMessage(message, Common.openOutputPanel, Common.selectPythonInterpreter);
if (result === Common.openOutputPanel) {
await executeCommand(Commands.ViewOutput);
} else if (result === Common.selectPythonInterpreter) {
await executeCommand(Commands.Set_Interpreter);
}
}
export function getVenvPath(workspaceFolder: WorkspaceFolder): string {
return path.join(workspaceFolder.uri.fsPath, '.venv');
}
export async function hasVenv(workspaceFolder: WorkspaceFolder): Promise<boolean> {
return fs.pathExists(path.join(getVenvPath(workspaceFolder), 'pyvenv.cfg'));
}
export function getVenvExecutable(workspaceFolder: WorkspaceFolder): string {
if (isWindows()) {
return path.join(getVenvPath(workspaceFolder), 'Scripts', 'python.exe');
}
return path.join(getVenvPath(workspaceFolder), 'bin', 'python');
}
export function getPrefixCondaEnvPath(workspaceFolder: WorkspaceFolder): string {
return path.join(workspaceFolder.uri.fsPath, '.conda');
}
export async function hasPrefixCondaEnv(workspaceFolder: WorkspaceFolder): Promise<boolean> {
return fs.pathExists(getPrefixCondaEnvPath(workspaceFolder));
}