forked from DonJayamanne/vscode-python-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobalInstalledEnvs.ts
More file actions
46 lines (43 loc) · 2.02 KB
/
Copy pathglobalInstalledEnvs.ts
File metadata and controls
46 lines (43 loc) · 2.02 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { getSearchPathEntries } from '../../../common/utils/exec';
import { getOSType, OSType } from '../../../common/utils/platform';
import { isParentPath } from '../externalDependencies';
import { commonPosixBinPaths } from '../posixUtils';
import { isPyenvShimDir } from './pyenv';
/**
* Checks if the given interpreter belongs to known globally installed types. If an global
* executable is discoverable, we consider it as global type.
* @param {string} interpreterPath: Absolute path to the python interpreter.
* @returns {boolean} : Returns true if the interpreter belongs to a venv environment.
*/
export async function isGloballyInstalledEnv(executablePath: string): Promise<boolean> {
// Identifying this type is not important, as the extension treats `Global` and `Unknown`
// types the same way. This is only required for telemetry. As windows registry is known
// to be slow, we do not want to unnecessarily block on that by default, hence skip this
// step.
// if (getOSType() === OSType.Windows) {
// if (await isFoundInWindowsRegistry(executablePath)) {
// return true;
// }
// }
return isFoundInPathEnvVar(executablePath);
}
async function isFoundInPathEnvVar(executablePath: string): Promise<boolean> {
let searchPathEntries: string[] = [];
if (getOSType() === OSType.Windows) {
searchPathEntries = getSearchPathEntries();
} else {
searchPathEntries = await commonPosixBinPaths();
}
// Filter out pyenv shims. They are not actual python binaries, they are used to launch
// the binaries specified in .python-version file in the cwd. We should not be reporting
// those binaries as environments.
searchPathEntries = searchPathEntries.filter((dirname) => !isPyenvShimDir(dirname));
for (const searchPath of searchPathEntries) {
if (isParentPath(executablePath, searchPath)) {
return true;
}
}
return false;
}