forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
141 lines (133 loc) · 4 KB
/
index.ts
File metadata and controls
141 lines (133 loc) · 4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Architecture } from '../../common/utils/platform';
import { PythonEnvType } from '../base/info';
import { PythonVersion } from './pythonVersion';
/**
* The supported Python environment types.
*/
export enum EnvironmentType {
Unknown = 'Unknown',
Conda = 'Conda',
VirtualEnv = 'VirtualEnv',
Pipenv = 'PipEnv',
Pyenv = 'Pyenv',
Venv = 'Venv',
MicrosoftStore = 'MicrosoftStore',
Poetry = 'Poetry',
Hatch = 'Hatch',
Pixi = 'Pixi',
VirtualEnvWrapper = 'VirtualEnvWrapper',
ActiveState = 'ActiveState',
Global = 'Global',
System = 'System',
}
/**
* These envs are only created for a specific workspace, which we're able to detect.
*/
export const workspaceVirtualEnvTypes = [EnvironmentType.Poetry, EnvironmentType.Pipenv, EnvironmentType.Pixi];
export const virtualEnvTypes = [
...workspaceVirtualEnvTypes,
EnvironmentType.Hatch, // This is also a workspace virtual env, but we're not treating it as such as of today.
EnvironmentType.Venv,
EnvironmentType.VirtualEnvWrapper,
EnvironmentType.Conda,
EnvironmentType.VirtualEnv,
];
/**
* The IModuleInstaller implementations.
*/
export enum ModuleInstallerType {
Unknown = 'Unknown',
Conda = 'Conda',
Pip = 'Pip',
Poetry = 'Poetry',
Pipenv = 'Pipenv',
Pixi = 'Pixi',
}
/**
* Details about a Python runtime.
*
* @prop path - the location of the executable file
* @prop version - the runtime version
* @prop sysVersion - the raw value of `sys.version`
* @prop architecture - of the host CPU (e.g. `x86`)
* @prop sysPrefix - the environment's install root (`sys.prefix`)
* @prop pipEnvWorkspaceFolder - the pipenv root, if applicable
*/
export type InterpreterInformation = {
path: string;
version?: PythonVersion;
sysVersion?: string;
architecture: Architecture;
sysPrefix: string;
pipEnvWorkspaceFolder?: string;
};
/**
* Details about a Python environment.
*
* @prop companyDisplayName - the user-facing name of the distro publisher
* @prop displayName - the user-facing name for the environment
* @prop envType - the kind of Python environment
* @prop envName - the environment's name, if applicable (else `envPath` is set)
* @prop envPath - the environment's root dir, if applicable (else `envName`)
* @prop cachedEntry - whether or not the info came from a cache
* @prop type - the type of Python environment, if applicable
*/
// Note that "cachedEntry" is specific to the caching machinery
// and doesn't really belong here.
export type PythonEnvironment = InterpreterInformation & {
id?: string;
companyDisplayName?: string;
displayName?: string;
detailedDisplayName?: string;
envType: EnvironmentType;
envName?: string;
envPath?: string;
cachedEntry?: boolean;
type?: PythonEnvType;
};
/**
* Convert the Python environment type to a user-facing name.
*/
export function getEnvironmentTypeName(environmentType: EnvironmentType): string {
switch (environmentType) {
case EnvironmentType.Conda: {
return 'conda';
}
case EnvironmentType.Pipenv: {
return 'Pipenv';
}
case EnvironmentType.Pyenv: {
return 'pyenv';
}
case EnvironmentType.Venv: {
return 'venv';
}
case EnvironmentType.VirtualEnv: {
return 'virtualenv';
}
case EnvironmentType.MicrosoftStore: {
return 'Microsoft Store';
}
case EnvironmentType.Poetry: {
return 'Poetry';
}
case EnvironmentType.Hatch: {
return 'Hatch';
}
case EnvironmentType.Pixi: {
return 'pixi';
}
case EnvironmentType.VirtualEnvWrapper: {
return 'virtualenvwrapper';
}
case EnvironmentType.ActiveState: {
return 'ActiveState';
}
default: {
return '';
}
}
}