forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.ts
214 lines (195 loc) · 6.01 KB
/
index.ts
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Uri } from 'vscode';
import { Architecture } from '../../../common/utils/platform';
import { BasicVersionInfo, VersionInfo } from '../../../common/utils/version';
/**
* IDs for the various supported Python environments.
*/
export enum PythonEnvKind {
Unknown = 'unknown',
// "global"
System = 'global-system',
MacDefault = 'global-mac-default',
WindowsStore = 'global-windows-store',
Pyenv = 'global-pyenv',
CondaBase = 'global-conda-base',
Poetry = 'global-poetry',
Custom = 'global-custom',
OtherGlobal = 'global-other',
// "virtual"
Venv = 'virt-venv',
VirtualEnv = 'virt-virtualenv',
VirtualEnvWrapper = 'virt-virtualenvwrapper',
Pipenv = 'virt-pipenv',
Conda = 'virt-conda',
OtherVirtual = 'virt-other',
}
export interface EnvPathType {
/**
* Path to environment folder or path to interpreter that uniquely identifies an environment.
* Virtual environments lacking an interpreter are identified by environment folder paths,
* whereas other envs can be identified using interpreter path.
*/
path: string;
pathType: 'envFolderPath' | 'interpreterPath';
}
export const virtualEnvKinds = [
PythonEnvKind.Poetry,
PythonEnvKind.Pipenv,
PythonEnvKind.Venv,
PythonEnvKind.VirtualEnvWrapper,
PythonEnvKind.Conda,
PythonEnvKind.VirtualEnv,
];
export const globallyInstalledEnvKinds = [
PythonEnvKind.OtherGlobal,
PythonEnvKind.Unknown,
PythonEnvKind.WindowsStore,
PythonEnvKind.System,
PythonEnvKind.Custom,
];
/**
* Information about a file.
*/
export type FileInfo = {
filename: string;
ctime: number;
mtime: number;
};
/**
* Information about a Python binary/executable.
*/
export type PythonExecutableInfo = FileInfo & {
sysPrefix: string;
};
/**
* Source types indicating how a particular environment was discovered.
*
* Notes: This is used in auto-selection to figure out which python to select.
* We added this field to support the existing mechanism in the extension to
* calculate the auto-select python.
*/
export enum PythonEnvSource {
/**
* Environment was found via PATH env variable
*/
PathEnvVar = 'path env var',
/**
* Environment was found in windows registry
*/
WindowsRegistry = 'windows registry',
// If source turns out to be useful we will expand this enum to contain more details sources.
}
/**
* The most fundamental information about a Python environment.
*
* You should expect these objects to be complete (no empty props).
* Note that either `name` or `location` must be non-empty, though
* the other *can* be empty.
*
* @prop id - the env's unique ID
* @prop kind - the env's kind
* @prop executable - info about the env's Python binary
* @prop name - the env's distro-specific name, if any
* @prop location - the env's location (on disk), if relevant
* @prop source - the locator[s] which found the environment.
*/
type PythonEnvBaseInfo = {
id?: string;
kind: PythonEnvKind;
executable: PythonExecutableInfo;
// One of (name, location) must be non-empty.
name: string;
location: string;
// Other possible fields:
// * managed: boolean (if the env is "managed")
// * parent: PythonEnvBaseInfo (the env from which this one was created)
// * binDir: string (where env-installed executables are found)
source: PythonEnvSource[];
};
/**
* The possible Python release levels.
*/
export enum PythonReleaseLevel {
Alpha = 'alpha',
Beta = 'beta',
Candidate = 'candidate',
Final = 'final',
}
/**
* Release information for a Python version.
*/
export type PythonVersionRelease = {
level: PythonReleaseLevel;
serial: number;
};
/**
* Version information for a Python build/installation.
*
* @prop sysVersion - the raw text from `sys.version`
*/
export type PythonVersion = BasicVersionInfo & {
release?: PythonVersionRelease;
sysVersion?: string;
};
/**
* Information for a Python build/installation.
*/
type PythonBuildInfo = {
version: PythonVersion; // incl. raw, AKA sys.version
arch: Architecture;
};
/**
* Meta information about a Python distribution.
*
* @prop org - the name of the distro's creator/publisher
* @prop defaultDisplayName - the text to use when showing the distro to users
*/
type PythonDistroMetaInfo = {
org: string;
defaultDisplayName?: string;
};
/**
* Information about an installed Python distribution.
*
* @prop version - the installed *distro* version (not the Python version)
* @prop binDir - where to look for the distro's executables (i.e. tools)
*/
export type PythonDistroInfo = PythonDistroMetaInfo & {
version?: VersionInfo;
binDir?: string;
};
type _PythonEnvInfo = PythonEnvBaseInfo & PythonBuildInfo;
/**
* All the available information about a Python environment.
*
* Note that not all the information will necessarily be filled in.
* Locators are only required to fill in the "base" info, though
* they will usually be able to provide the version as well.
*
* @prop distro - the installed Python distro that this env is using or belongs to
* @prop display - the text to use when showing the env to users
* @prop detailedDisplayName - display name containing all details
* @prop searchLocation - the root under which a locator found this env, if any
*/
export type PythonEnvInfo = _PythonEnvInfo & {
distro: PythonDistroInfo;
display?: string;
detailedDisplayName?: string;
searchLocation?: Uri;
};
/**
* A dummy python version object containing default fields.
*
* Note this object is immutable. So if it is assigned to another object, the properties of the other object
* also cannot be modified by reference. For eg. `otherVersionObject.major = 3` won't work.
*/
export const UNKNOWN_PYTHON_VERSION: PythonVersion = {
major: -1,
minor: -1,
micro: -1,
release: { level: PythonReleaseLevel.Final, serial: -1 },
sysVersion: undefined,
};
Object.freeze(UNKNOWN_PYTHON_VERSION);