@@ -13,15 +13,22 @@ import {
13
13
TriggerRefreshOptions ,
14
14
} from './base/locator' ;
15
15
import { PythonEnvCollectionChangedEvent } from './base/watcher' ;
16
- import { isNativeEnvInfo , NativeEnvInfo , NativePythonFinder } from './base/locators/common/nativePythonFinder' ;
16
+ import {
17
+ isNativeEnvInfo ,
18
+ NativeEnvInfo ,
19
+ NativeEnvManagerInfo ,
20
+ NativePythonFinder ,
21
+ } from './base/locators/common/nativePythonFinder' ;
17
22
import { createDeferred , Deferred } from '../common/utils/async' ;
18
23
import { Architecture } from '../common/utils/platform' ;
19
24
import { parseVersion } from './base/info/pythonVersion' ;
20
25
import { cache } from '../common/utils/decorators' ;
21
- import { traceError , traceLog } from '../logging' ;
26
+ import { traceError , traceLog , traceWarn } from '../logging' ;
22
27
import { StopWatch } from '../common/utils/stopWatch' ;
23
28
import { FileChangeType } from '../common/platform/fileSystemWatcher' ;
24
29
import { categoryToKind } from './base/locators/common/nativePythonUtils' ;
30
+ import { setCondaBinary } from './common/environmentManagers/conda' ;
31
+ import { setPyEnvBinary } from './common/environmentManagers/pyenv' ;
25
32
26
33
function makeExecutablePath ( prefix ?: string ) : string {
27
34
if ( ! prefix ) {
@@ -232,44 +239,10 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
232
239
setImmediate ( async ( ) => {
233
240
try {
234
241
for await ( const native of this . finder . refresh ( ) ) {
235
- if ( ! isNativeEnvInfo ( native ) || ! validEnv ( native ) ) {
236
- // eslint-disable-next-line no-continue
237
- continue ;
238
- }
239
- try {
240
- const envPath = native . executable ?? native . prefix ;
241
- const version = native . version ? parseVersion ( native . version ) : undefined ;
242
-
243
- if ( categoryToKind ( native . kind ) === PythonEnvKind . Conda && ! native . executable ) {
244
- // This is a conda env without python, no point trying to resolve this.
245
- // There is nothing to resolve
246
- this . addEnv ( native ) ;
247
- } else if (
248
- envPath &&
249
- ( ! version || version . major < 0 || version . minor < 0 || version . micro < 0 )
250
- ) {
251
- // We have a path, but no version info, try to resolve the environment.
252
- this . finder
253
- . resolve ( envPath )
254
- . then ( ( env ) => {
255
- if ( env ) {
256
- this . addEnv ( env ) ;
257
- }
258
- } )
259
- . ignoreErrors ( ) ;
260
- } else if (
261
- envPath &&
262
- version &&
263
- version . major >= 0 &&
264
- version . minor >= 0 &&
265
- version . micro >= 0
266
- ) {
267
- this . addEnv ( native ) ;
268
- } else {
269
- traceError ( `Failed to process environment: ${ JSON . stringify ( native ) } ` ) ;
270
- }
271
- } catch ( err ) {
272
- traceError ( `Failed to process environment: ${ err } ` ) ;
242
+ if ( isNativeEnvInfo ( native ) ) {
243
+ this . processEnv ( native ) ;
244
+ } else {
245
+ this . processEnvManager ( native ) ;
273
246
}
274
247
}
275
248
this . _refreshPromise ?. resolve ( ) ;
@@ -286,6 +259,57 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
286
259
return this . _refreshPromise ?. promise ;
287
260
}
288
261
262
+ private processEnv ( native : NativeEnvInfo ) : void {
263
+ if ( ! validEnv ( native ) ) {
264
+ return ;
265
+ }
266
+
267
+ try {
268
+ const envPath = native . executable ?? native . prefix ;
269
+ const version = native . version ? parseVersion ( native . version ) : undefined ;
270
+
271
+ if ( categoryToKind ( native . kind ) === PythonEnvKind . Conda && ! native . executable ) {
272
+ // This is a conda env without python, no point trying to resolve this.
273
+ // There is nothing to resolve
274
+ this . addEnv ( native ) ;
275
+ } else if ( envPath && ( ! version || version . major < 0 || version . minor < 0 || version . micro < 0 ) ) {
276
+ // We have a path, but no version info, try to resolve the environment.
277
+ this . finder
278
+ . resolve ( envPath )
279
+ . then ( ( env ) => {
280
+ if ( env ) {
281
+ this . addEnv ( env ) ;
282
+ }
283
+ } )
284
+ . ignoreErrors ( ) ;
285
+ } else if ( envPath && version && version . major >= 0 && version . minor >= 0 && version . micro >= 0 ) {
286
+ this . addEnv ( native ) ;
287
+ } else {
288
+ traceError ( `Failed to process environment: ${ JSON . stringify ( native ) } ` ) ;
289
+ }
290
+ } catch ( err ) {
291
+ traceError ( `Failed to process environment: ${ err } ` ) ;
292
+ }
293
+ }
294
+
295
+ // eslint-disable-next-line class-methods-use-this
296
+ private processEnvManager ( native : NativeEnvManagerInfo ) {
297
+ const tool = native . tool . toLowerCase ( ) ;
298
+ switch ( tool ) {
299
+ case 'conda' :
300
+ traceLog ( `Conda environment manager found at: ${ native . executable } ` ) ;
301
+ setCondaBinary ( native . executable ) ;
302
+ break ;
303
+ case 'pyenv' :
304
+ traceLog ( `Pyenv environment manager found at: ${ native . executable } ` ) ;
305
+ setPyEnvBinary ( native . executable ) ;
306
+ break ;
307
+ default :
308
+ traceWarn ( `Unknown environment manager: ${ native . tool } ` ) ;
309
+ break ;
310
+ }
311
+ }
312
+
289
313
getEnvs ( _query ?: PythonLocatorQuery ) : PythonEnvInfo [ ] {
290
314
return this . _envs ;
291
315
}
0 commit comments