@@ -20,14 +20,14 @@ import {
20
20
NativePythonFinder ,
21
21
} from './base/locators/common/nativePythonFinder' ;
22
22
import { createDeferred , Deferred } from '../common/utils/async' ;
23
- import { Architecture , getUserHomeDir } from '../common/utils/platform' ;
23
+ import { Architecture , getPathEnvVariable , getUserHomeDir } from '../common/utils/platform' ;
24
24
import { parseVersion } from './base/info/pythonVersion' ;
25
25
import { cache } from '../common/utils/decorators' ;
26
26
import { traceError , traceInfo , traceLog , traceWarn } from '../logging' ;
27
27
import { StopWatch } from '../common/utils/stopWatch' ;
28
28
import { FileChangeType } from '../common/platform/fileSystemWatcher' ;
29
29
import { categoryToKind , NativePythonEnvironmentKind } from './base/locators/common/nativePythonUtils' ;
30
- import { getCondaEnvDirs , setCondaBinary } from './common/environmentManagers/conda' ;
30
+ import { getCondaEnvDirs , getCondaPathSetting , setCondaBinary } from './common/environmentManagers/conda' ;
31
31
import { setPyEnvBinary } from './common/environmentManagers/pyenv' ;
32
32
import {
33
33
createPythonWatcher ,
@@ -166,6 +166,12 @@ function isSubDir(pathToCheck: string | undefined, parents: string[]): boolean {
166
166
} ) ;
167
167
}
168
168
169
+ function foundOnPath ( fsPath : string ) : boolean {
170
+ const paths = getPathEnvVariable ( ) . map ( ( p ) => path . normalize ( p ) . toLowerCase ( ) ) ;
171
+ const normalized = path . normalize ( fsPath ) . toLowerCase ( ) ;
172
+ return paths . some ( ( p ) => normalized . includes ( p ) ) ;
173
+ }
174
+
169
175
function getName ( nativeEnv : NativeEnvInfo , kind : PythonEnvKind , condaEnvDirs : string [ ] ) : string {
170
176
if ( nativeEnv . name ) {
171
177
return nativeEnv . name ;
@@ -387,13 +393,36 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
387
393
return undefined ;
388
394
}
389
395
396
+ private condaPathAlreadySet : string | undefined ;
397
+
390
398
// eslint-disable-next-line class-methods-use-this
391
399
private processEnvManager ( native : NativeEnvManagerInfo ) {
392
400
const tool = native . tool . toLowerCase ( ) ;
393
401
switch ( tool ) {
394
402
case 'conda' :
395
- traceLog ( `Conda environment manager found at: ${ native . executable } ` ) ;
396
- setCondaBinary ( native . executable ) ;
403
+ {
404
+ traceLog ( `Conda environment manager found at: ${ native . executable } ` ) ;
405
+ const settingPath = getCondaPathSetting ( ) ;
406
+ if ( ! this . condaPathAlreadySet ) {
407
+ if ( settingPath === '' || settingPath === undefined ) {
408
+ if ( foundOnPath ( native . executable ) ) {
409
+ setCondaBinary ( native . executable ) ;
410
+ this . condaPathAlreadySet = native . executable ;
411
+ traceInfo ( `Using conda: ${ native . executable } ` ) ;
412
+ } else {
413
+ traceInfo ( `Conda not found on PATH, skipping: ${ native . executable } ` ) ;
414
+ traceInfo (
415
+ 'You can set the path to conda using the setting: `python.condaPath` if you want to use a different conda binary' ,
416
+ ) ;
417
+ }
418
+ } else {
419
+ traceInfo ( `Using conda from setting: ${ settingPath } ` ) ;
420
+ this . condaPathAlreadySet = settingPath ;
421
+ }
422
+ } else {
423
+ traceInfo ( `Conda set to: ${ this . condaPathAlreadySet } ` ) ;
424
+ }
425
+ }
397
426
break ;
398
427
case 'pyenv' :
399
428
traceLog ( `Pyenv environment manager found at: ${ native . executable } ` ) ;
0 commit comments