@@ -20,14 +20,14 @@ import {
2020 NativePythonFinder ,
2121} from './base/locators/common/nativePythonFinder' ;
2222import { createDeferred , Deferred } from '../common/utils/async' ;
23- import { Architecture , getUserHomeDir } from '../common/utils/platform' ;
23+ import { Architecture , getPathEnvVariable , getUserHomeDir } from '../common/utils/platform' ;
2424import { parseVersion } from './base/info/pythonVersion' ;
2525import { cache } from '../common/utils/decorators' ;
2626import { traceError , traceInfo , traceLog , traceWarn } from '../logging' ;
2727import { StopWatch } from '../common/utils/stopWatch' ;
2828import { FileChangeType } from '../common/platform/fileSystemWatcher' ;
2929import { categoryToKind , NativePythonEnvironmentKind } from './base/locators/common/nativePythonUtils' ;
30- import { getCondaEnvDirs , setCondaBinary } from './common/environmentManagers/conda' ;
30+ import { getCondaEnvDirs , getCondaPathSetting , setCondaBinary } from './common/environmentManagers/conda' ;
3131import { setPyEnvBinary } from './common/environmentManagers/pyenv' ;
3232import {
3333 createPythonWatcher ,
@@ -166,6 +166,12 @@ function isSubDir(pathToCheck: string | undefined, parents: string[]): boolean {
166166 } ) ;
167167}
168168
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+
169175function getName ( nativeEnv : NativeEnvInfo , kind : PythonEnvKind , condaEnvDirs : string [ ] ) : string {
170176 if ( nativeEnv . name ) {
171177 return nativeEnv . name ;
@@ -387,13 +393,36 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
387393 return undefined ;
388394 }
389395
396+ private condaPathAlreadySet : string | undefined ;
397+
390398 // eslint-disable-next-line class-methods-use-this
391399 private processEnvManager ( native : NativeEnvManagerInfo ) {
392400 const tool = native . tool . toLowerCase ( ) ;
393401 switch ( tool ) {
394402 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+ }
397426 break ;
398427 case 'pyenv' :
399428 traceLog ( `Pyenv environment manager found at: ${ native . executable } ` ) ;
0 commit comments