@@ -37,6 +37,8 @@ export function buildEnvInfo(init?: {
37
37
} ,
38
38
name : '' ,
39
39
location : '' ,
40
+ searchLocation : undefined ,
41
+ defaultDisplayName : undefined ,
40
42
version : {
41
43
major : - 1 ,
42
44
minor : - 1 ,
@@ -65,7 +67,7 @@ export function buildEnvInfo(init?: {
65
67
export function copyEnvInfo (
66
68
env : PythonEnvInfo ,
67
69
updates ?: {
68
- kind ?: PythonEnvKind ,
70
+ kind ?: PythonEnvKind ;
69
71
} ,
70
72
) : PythonEnvInfo {
71
73
// We don't care whether or not extra/hidden properties
@@ -77,12 +79,15 @@ export function copyEnvInfo(
77
79
return copied ;
78
80
}
79
81
80
- function updateEnv ( env : PythonEnvInfo , updates : {
81
- kind ?: PythonEnvKind ;
82
- executable ?: string ;
83
- location ?: string ;
84
- version ?: PythonVersion ;
85
- } ) : void {
82
+ function updateEnv (
83
+ env : PythonEnvInfo ,
84
+ updates : {
85
+ kind ?: PythonEnvKind ;
86
+ executable ?: string ;
87
+ location ?: string ;
88
+ version ?: PythonVersion ;
89
+ } ,
90
+ ) : void {
86
91
if ( updates . kind !== undefined ) {
87
92
env . kind = updates . kind ;
88
93
}
@@ -109,7 +114,9 @@ export function getMinimalPartialInfo(env: string | Partial<PythonEnvInfo>): Par
109
114
return undefined ;
110
115
}
111
116
return {
112
- executable : { filename : env , sysPrefix : '' , ctime : - 1 , mtime : - 1 } ,
117
+ executable : {
118
+ filename : env , sysPrefix : '' , ctime : - 1 , mtime : - 1 ,
119
+ } ,
113
120
} ;
114
121
}
115
122
if ( env . executable === undefined ) {
@@ -136,7 +143,7 @@ export function getMinimalPartialInfo(env: string | Partial<PythonEnvInfo>): Par
136
143
export function areSameEnv (
137
144
left : string | Partial < PythonEnvInfo > ,
138
145
right : string | Partial < PythonEnvInfo > ,
139
- allowPartialMatch ?: boolean ,
146
+ allowPartialMatch = true ,
140
147
) : boolean | undefined {
141
148
const leftInfo = getMinimalPartialInfo ( left ) ;
142
149
const rightInfo = getMinimalPartialInfo ( right ) ;
@@ -173,7 +180,7 @@ export function areSameEnv(
173
180
* weighted by most important to least important fields.
174
181
* Wn > Wn-1 + Wn-2 + ... W0
175
182
*/
176
- function getPythonVersionInfoHeuristic ( version :PythonVersion ) : number {
183
+ function getPythonVersionInfoHeuristic ( version : PythonVersion ) : number {
177
184
let infoLevel = 0 ;
178
185
if ( version . major > 0 ) {
179
186
infoLevel += 20 ; // W4
@@ -205,7 +212,7 @@ function getPythonVersionInfoHeuristic(version:PythonVersion): number {
205
212
* weighted by most important to least important fields.
206
213
* Wn > Wn-1 + Wn-2 + ... W0
207
214
*/
208
- function getFileInfoHeuristic ( file :FileInfo ) : number {
215
+ function getFileInfoHeuristic ( file : FileInfo ) : number {
209
216
let infoLevel = 0 ;
210
217
if ( file . filename . length > 0 ) {
211
218
infoLevel += 5 ; // W2
@@ -229,7 +236,7 @@ function getFileInfoHeuristic(file:FileInfo): number {
229
236
* weighted by most important to least important fields.
230
237
* Wn > Wn-1 + Wn-2 + ... W0
231
238
*/
232
- function getDistroInfoHeuristic ( distro :PythonDistroInfo ) :number {
239
+ function getDistroInfoHeuristic ( distro : PythonDistroInfo ) : number {
233
240
let infoLevel = 0 ;
234
241
if ( distro . org . length > 0 ) {
235
242
infoLevel += 20 ; // W3
@@ -250,62 +257,6 @@ function getDistroInfoHeuristic(distro:PythonDistroInfo):number {
250
257
return infoLevel ;
251
258
}
252
259
253
- /**
254
- * Gets a prioritized list of environment types for identification.
255
- * @returns {PythonEnvKind[] } : List of environments ordered by identification priority
256
- *
257
- * Remarks: This is the order of detection based on how the various distributions and tools
258
- * configure the environment, and the fall back for identification.
259
- * Top level we have the following environment types, since they leave a unique signature
260
- * in the environment or * use a unique path for the environments they create.
261
- * 1. Conda
262
- * 2. Windows Store
263
- * 3. PipEnv
264
- * 4. Pyenv
265
- * 5. Poetry
266
- *
267
- * Next level we have the following virtual environment tools. The are here because they
268
- * are consumed by the tools above, and can also be used independently.
269
- * 1. venv
270
- * 2. virtualenvwrapper
271
- * 3. virtualenv
272
- *
273
- * Last category is globally installed python, or system python.
274
- */
275
- export function getPrioritizedEnvironmentKind ( ) : PythonEnvKind [ ] {
276
- return [
277
- PythonEnvKind . CondaBase ,
278
- PythonEnvKind . Conda ,
279
- PythonEnvKind . WindowsStore ,
280
- PythonEnvKind . Pipenv ,
281
- PythonEnvKind . Pyenv ,
282
- PythonEnvKind . Poetry ,
283
- PythonEnvKind . Venv ,
284
- PythonEnvKind . VirtualEnvWrapper ,
285
- PythonEnvKind . VirtualEnv ,
286
- PythonEnvKind . OtherVirtual ,
287
- PythonEnvKind . OtherGlobal ,
288
- PythonEnvKind . MacDefault ,
289
- PythonEnvKind . System ,
290
- PythonEnvKind . Custom ,
291
- PythonEnvKind . Unknown ,
292
- ] ;
293
- }
294
-
295
- /**
296
- * Selects an environment based on the environment selection priority. This should
297
- * match the priority in the environment identifier.
298
- */
299
- export function sortEnvInfoByPriority ( ...envs : PythonEnvInfo [ ] ) : PythonEnvInfo [ ] {
300
- // tslint:disable-next-line: no-suspicious-comment
301
- // TODO: When we consolidate the PythonEnvKind and EnvironmentType we should have
302
- // one location where we define priority and
303
- const envKindByPriority :PythonEnvKind [ ] = getPrioritizedEnvironmentKind ( ) ;
304
- return envs . sort (
305
- ( a :PythonEnvInfo , b :PythonEnvInfo ) => envKindByPriority . indexOf ( a . kind ) - envKindByPriority . indexOf ( b . kind ) ,
306
- ) ;
307
- }
308
-
309
260
/**
310
261
* Merges properties of the `target` environment and `other` environment and returns the merged environment.
311
262
* if the value in the `target` environment is not defined or has less information. This does not mutate
@@ -318,18 +269,19 @@ export function mergeEnvironments(target: PythonEnvInfo, other: PythonEnvInfo):
318
269
319
270
const version = cloneDeep (
320
271
getPythonVersionInfoHeuristic ( target . version ) > getPythonVersionInfoHeuristic ( other . version )
321
- ? target . version : other . version ,
272
+ ? target . version
273
+ : other . version ,
322
274
) ;
323
275
324
276
const executable = cloneDeep (
325
277
getFileInfoHeuristic ( target . executable ) > getFileInfoHeuristic ( other . executable )
326
- ? target . executable : other . executable ,
278
+ ? target . executable
279
+ : other . executable ,
327
280
) ;
328
281
executable . sysPrefix = target . executable . sysPrefix ?? other . executable . sysPrefix ;
329
282
330
283
const distro = cloneDeep (
331
- getDistroInfoHeuristic ( target . distro ) > getDistroInfoHeuristic ( other . distro )
332
- ? target . distro : other . distro ,
284
+ getDistroInfoHeuristic ( target . distro ) > getDistroInfoHeuristic ( other . distro ) ? target . distro : other . distro ,
333
285
) ;
334
286
335
287
merged . arch = merged . arch === Architecture . Unknown ? other . arch : target . arch ;
@@ -341,8 +293,8 @@ export function mergeEnvironments(target: PythonEnvInfo, other: PythonEnvInfo):
341
293
// preferred env based on kind.
342
294
merged . kind = target . kind ;
343
295
344
- merged . location = merged . location ?? other . location ;
345
- merged . name = merged . name ?? other . name ;
296
+ merged . location = merged . location . length ? merged . location : other . location ;
297
+ merged . name = merged . name . length ? merged . name : other . name ;
346
298
merged . searchLocation = merged . searchLocation ?? other . searchLocation ;
347
299
merged . version = version ;
348
300
0 commit comments