@@ -139,14 +139,21 @@ async function resolveGloballyInstalledEnv(env: BasicEnvInfo): Promise<PythonEnv
139
139
const { executablePath } = env ;
140
140
let version ;
141
141
try {
142
- version = parseVersionFromExecutable ( executablePath ) ;
142
+ version = env . version ?? parseVersionFromExecutable ( executablePath ) ;
143
143
} catch {
144
144
version = UNKNOWN_PYTHON_VERSION ;
145
145
}
146
146
const envInfo = buildEnvInfo ( {
147
147
kind : env . kind ,
148
+ name : env . name ,
149
+ display : env . displayName ,
150
+ sysPrefix : env . envPath ,
151
+ location : env . envPath ,
152
+ searchLocation : env . searchLocation ,
148
153
version,
149
154
executable : executablePath ,
155
+ pythonRunCommand : env . pythonRunCommand ,
156
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
150
157
} ) ;
151
158
return envInfo ;
152
159
}
@@ -155,17 +162,59 @@ async function resolveSimpleEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
155
162
const { executablePath, kind } = env ;
156
163
const envInfo = buildEnvInfo ( {
157
164
kind,
158
- version : await getPythonVersionFromPath ( executablePath ) ,
165
+ version : env . version ?? ( await getPythonVersionFromPath ( executablePath ) ) ,
159
166
executable : executablePath ,
167
+ sysPrefix : env . envPath ,
168
+ location : env . envPath ,
169
+ display : env . displayName ,
170
+ searchLocation : env . searchLocation ,
171
+ pythonRunCommand : env . pythonRunCommand ,
172
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
173
+ name : env . name ,
160
174
type : PythonEnvType . Virtual ,
161
175
} ) ;
162
- const location = getEnvironmentDirFromPath ( executablePath ) ;
176
+ const location = env . envPath ?? getEnvironmentDirFromPath ( executablePath ) ;
163
177
envInfo . location = location ;
164
178
envInfo . name = path . basename ( location ) ;
165
179
return envInfo ;
166
180
}
167
181
168
182
async function resolveCondaEnv ( env : BasicEnvInfo ) : Promise < PythonEnvInfo > {
183
+ if ( env . identifiedUsingNativeLocator ) {
184
+ // New approach using native locator.
185
+ const executable = env . executablePath ;
186
+ const envPath = env . envPath ?? getEnvironmentDirFromPath ( executable ) ;
187
+ // TODO: Hacky, `executable` is never undefined in the typedef,
188
+ // However, in reality with native locator this can be undefined.
189
+ const version = env . version ?? ( executable ? await getPythonVersionFromPath ( executable ) : undefined ) ;
190
+ const info = buildEnvInfo ( {
191
+ executable,
192
+ kind : PythonEnvKind . Conda ,
193
+ org : AnacondaCompanyName ,
194
+ location : envPath ,
195
+ sysPrefix : envPath ,
196
+ display : env . displayName ,
197
+ pythonRunCommand : env . pythonRunCommand ,
198
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
199
+ searchLocation : env . searchLocation ,
200
+ source : [ ] ,
201
+ version,
202
+ type : PythonEnvType . Conda ,
203
+ name : env . name ,
204
+ } ) ;
205
+
206
+ if ( env . envPath && executable && path . basename ( executable ) === executable ) {
207
+ // For environments without python, set ID using the predicted executable path after python is installed.
208
+ // Another alternative could've been to set ID of all conda environments to the environment path, as that
209
+ // remains constant even after python installation.
210
+ const predictedExecutable = getCondaInterpreterPath ( env . envPath ) ;
211
+ info . id = getEnvID ( predictedExecutable , env . envPath ) ;
212
+ }
213
+ return info ;
214
+ }
215
+
216
+ // Old approach (without native locator).
217
+ // In this approach we need to find conda.
169
218
const { executablePath } = env ;
170
219
const conda = await Conda . getConda ( ) ;
171
220
if ( conda === undefined ) {
@@ -210,18 +259,26 @@ async function resolveCondaEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
210
259
211
260
async function resolvePyenvEnv ( env : BasicEnvInfo ) : Promise < PythonEnvInfo > {
212
261
const { executablePath } = env ;
213
- const location = getEnvironmentDirFromPath ( executablePath ) ;
262
+ const location = env . envPath ?? getEnvironmentDirFromPath ( executablePath ) ;
214
263
const name = path . basename ( location ) ;
215
264
216
265
// The sub-directory name sometimes can contain distro and python versions.
217
266
// here we attempt to extract the texts out of the name.
218
267
const versionStrings = parsePyenvVersion ( name ) ;
219
268
220
269
const envInfo = buildEnvInfo ( {
221
- kind : PythonEnvKind . Pyenv ,
270
+ // If using native resolver, then we can get the kind from the native resolver.
271
+ // E.g. pyenv can have conda environments as well.
272
+ kind : env . identifiedUsingNativeLocator && env . kind ? env . kind : PythonEnvKind . Pyenv ,
222
273
executable : executablePath ,
223
274
source : [ ] ,
224
275
location,
276
+ searchLocation : env . searchLocation ,
277
+ sysPrefix : env . envPath ,
278
+ display : env . displayName ,
279
+ name : env . name ,
280
+ pythonRunCommand : env . pythonRunCommand ,
281
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
225
282
// Pyenv environments can fall in to these three categories:
226
283
// 1. Global Installs : These are environments that are created when you install
227
284
// a supported python distribution using `pyenv install <distro>` command.
@@ -240,14 +297,17 @@ async function resolvePyenvEnv(env: BasicEnvInfo): Promise<PythonEnvInfo> {
240
297
//
241
298
// Here we look for near by files, or config files to see if we can get python version info
242
299
// without running python itself.
243
- version : await getPythonVersionFromPath ( executablePath , versionStrings ?. pythonVer ) ,
300
+ version : env . version ?? ( await getPythonVersionFromPath ( executablePath , versionStrings ?. pythonVer ) ) ,
244
301
org : versionStrings && versionStrings . distro ? versionStrings . distro : '' ,
245
302
} ) ;
246
303
247
- if ( await isBaseCondaPyenvEnvironment ( executablePath ) ) {
248
- envInfo . name = 'base' ;
249
- } else {
250
- envInfo . name = name ;
304
+ // Do this only for the old approach, when not using native locators.
305
+ if ( ! env . identifiedUsingNativeLocator ) {
306
+ if ( await isBaseCondaPyenvEnvironment ( executablePath ) ) {
307
+ envInfo . name = 'base' ;
308
+ } else {
309
+ envInfo . name = name ;
310
+ }
251
311
}
252
312
return envInfo ;
253
313
}
@@ -256,6 +316,14 @@ async function resolveActiveStateEnv(env: BasicEnvInfo): Promise<PythonEnvInfo>
256
316
const info = buildEnvInfo ( {
257
317
kind : env . kind ,
258
318
executable : env . executablePath ,
319
+ display : env . displayName ,
320
+ version : env . version ,
321
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
322
+ location : env . envPath ,
323
+ name : env . name ,
324
+ pythonRunCommand : env . pythonRunCommand ,
325
+ searchLocation : env . searchLocation ,
326
+ sysPrefix : env . envPath ,
259
327
} ) ;
260
328
const projects = await ActiveState . getState ( ) . then ( ( v ) => v ?. getProjects ( ) ) ;
261
329
if ( projects ) {
@@ -285,8 +353,15 @@ async function resolveMicrosoftStoreEnv(env: BasicEnvInfo): Promise<PythonEnvInf
285
353
return buildEnvInfo ( {
286
354
kind : PythonEnvKind . MicrosoftStore ,
287
355
executable : executablePath ,
288
- version : parsePythonVersionFromPath ( executablePath ) ,
356
+ version : env . version ?? parsePythonVersionFromPath ( executablePath ) ,
289
357
org : 'Microsoft' ,
358
+ display : env . displayName ,
359
+ location : env . envPath ,
360
+ sysPrefix : env . envPath ,
361
+ searchLocation : env . searchLocation ,
362
+ name : env . name ,
363
+ pythonRunCommand : env . pythonRunCommand ,
364
+ identifiedUsingNativeLocator : env . identifiedUsingNativeLocator ,
290
365
arch : Architecture . x64 ,
291
366
source : [ PythonEnvSource . PathEnvVar ] ,
292
367
} ) ;
0 commit comments