@@ -25,7 +25,8 @@ const untildify: (value: string) => string = require('untildify');
2525
2626// This glob pattern will match all of the following:
2727// ~/anaconda/bin/conda, ~/anaconda3/bin/conda, ~/miniconda/bin/conda, ~/miniconda3/bin/conda
28- // /usr/share/anaconda/bin/conda, /usr/share/anaconda3/bin/conda, /usr/share/miniconda/bin/conda, /usr/share/miniconda3/bin/conda
28+ // /usr/share/anaconda/bin/conda, /usr/share/anaconda3/bin/conda, /usr/share/miniconda/bin/conda,
29+ // /usr/share/miniconda3/bin/conda
2930
3031const condaGlobPathsForLinuxMac = [
3132 untildify ( '~/opt/*conda*/bin/conda' ) ,
@@ -62,6 +63,11 @@ interface IComponent {
6263 */
6364@injectable ( )
6465export class CondaService implements ICondaService {
66+ public get condaEnvironmentsFile ( ) : string | undefined {
67+ const homeDir = this . platform . isWindows ? process . env . USERPROFILE : process . env . HOME || process . env . HOMEPATH ;
68+ return homeDir ? path . join ( homeDir , '.conda' , 'environments.txt' ) : undefined ;
69+ }
70+
6571 private condaFile ?: Promise < string | undefined > ;
6672
6773 private isAvailable : boolean | undefined ;
@@ -83,9 +89,30 @@ export class CondaService implements ICondaService {
8389 this . addCondaPathChangedHandler ( ) ;
8490 }
8591
86- public get condaEnvironmentsFile ( ) : string | undefined {
87- const homeDir = this . platform . isWindows ? process . env . USERPROFILE : process . env . HOME || process . env . HOMEPATH ;
88- return homeDir ? path . join ( homeDir , '.conda' , 'environments.txt' ) : undefined ;
92+ /**
93+ * Return the highest Python version from the given list.
94+ */
95+ private static getLatestVersion ( interpreters : PythonEnvironment [ ] ) : PythonEnvironment | undefined {
96+ const sortedInterpreters = interpreters . slice ( ) ;
97+ // tslint:disable-next-line:no-non-null-assertion
98+ sortedInterpreters . sort ( ( a , b ) => ( a . version && b . version ? compare ( a . version . raw , b . version . raw ) : 0 ) ) ;
99+ if ( sortedInterpreters . length > 0 ) {
100+ return sortedInterpreters [ sortedInterpreters . length - 1 ] ;
101+ }
102+
103+ return undefined ;
104+ }
105+
106+ /**
107+ * Is the given interpreter from conda?
108+ */
109+ private static detectCondaEnvironment ( env : PythonEnvironment ) : boolean {
110+ return (
111+ env . envType === EnvironmentType . Conda
112+ || ( env . displayName ? env . displayName : '' ) . toUpperCase ( ) . indexOf ( 'ANACONDA' ) >= 0
113+ || ( env . companyDisplayName ? env . companyDisplayName : '' ) . toUpperCase ( ) . indexOf ( 'ANACONDA' ) >= 0
114+ || ( env . companyDisplayName ? env . companyDisplayName : '' ) . toUpperCase ( ) . indexOf ( 'CONTINUUM' ) >= 0
115+ ) ;
89116 }
90117
91118 /**
@@ -94,7 +121,7 @@ export class CondaService implements ICondaService {
94121 * Called by VS Code to indicate it is done with the resource.
95122 */
96123 // tslint:disable-next-line:no-empty
97- public dispose ( ) { }
124+ public dispose ( ) : void { } // eslint-disable-line
98125
99126 /**
100127 * Return the path to the "conda file".
@@ -116,8 +143,9 @@ export class CondaService implements ICondaService {
116143 return this . isAvailable ;
117144 }
118145 return this . getCondaVersion ( )
119- . then ( ( version ) => ( this . isAvailable = version !== undefined ) )
120- . catch ( ( ) => ( this . isAvailable = false ) ) ;
146+
147+ . then ( ( version ) => ( this . isAvailable = version !== undefined ) ) // eslint-disable-line no-return-assign
148+ . catch ( ( ) => ( this . isAvailable = false ) ) ; // eslint-disable-line no-return-assign
121149 }
122150
123151 /**
@@ -143,7 +171,7 @@ export class CondaService implements ICondaService {
143171 versionString = stdOut && stdOut . startsWith ( 'conda ' ) ? stdOut . substring ( 'conda ' . length ) . trim ( ) : stdOut ;
144172 }
145173 if ( ! versionString ) {
146- return ;
174+ return undefined ;
147175 }
148176 const version = parse ( versionString , true ) ;
149177 if ( version ) {
@@ -157,7 +185,7 @@ export class CondaService implements ICondaService {
157185 /**
158186 * Can the shell find conda (to run it)?
159187 */
160- public async isCondaInCurrentPath ( ) {
188+ public async isCondaInCurrentPath ( ) : Promise < boolean > {
161189 const processService = await this . processServiceFactory . create ( ) ;
162190 return processService
163191 . exec ( 'conda' , [ '--version' ] )
@@ -181,6 +209,7 @@ export class CondaService implements ICondaService {
181209 // Failed because either:
182210 // 1. conda is not installed.
183211 // 2. `conda info --json` has changed signature.
212+ return undefined ;
184213 }
185214 }
186215
@@ -212,7 +241,7 @@ export class CondaService implements ICondaService {
212241 }
213242 const isCondaEnv = await this . isCondaEnvironment ( interpreterPath ) ;
214243 if ( ! isCondaEnv ) {
215- return ;
244+ return undefined ;
216245 }
217246 let environments = await this . getCondaEnvironments ( false ) ;
218247 const dir = path . dirname ( interpreterPath ) ;
@@ -239,6 +268,7 @@ export class CondaService implements ICondaService {
239268
240269 // If still not available, then the user created the env after starting vs code.
241270 // The only solution is to get the user to re-start vscode.
271+ return undefined ;
242272 }
243273
244274 /**
@@ -249,8 +279,7 @@ export class CondaService implements ICondaService {
249279 // Global cache.
250280 const globalPersistence = this . persistentStateFactory . createGlobalPersistentState < {
251281 data : CondaEnvironmentInfo [ ] | undefined ;
252- // tslint:disable-next-line:no-any
253- } > ( 'CONDA_ENVIRONMENTS' , undefined as any ) ;
282+ } > ( 'CONDA_ENVIRONMENTS' , undefined ) ;
254283 if ( ! ignoreCache && globalPersistence . value ) {
255284 return globalPersistence . value . data ;
256285 }
@@ -284,6 +313,7 @@ export class CondaService implements ICondaService {
284313 // 1. conda is not installed.
285314 // 2. `conda env list has changed signature.
286315 traceError ( 'Failed to get conda environment list from conda' , ex ) ;
316+ return undefined ;
287317 }
288318 }
289319
@@ -297,7 +327,9 @@ export class CondaService implements ICondaService {
297327 }
298328
299329 /**
300- * Get the conda exe from the path to an interpreter's python. This might be different than the globally registered conda.exe
330+ * Get the conda exe from the path to an interpreter's python. This might be different than the
331+ * globally registered conda.exe.
332+ *
301333 * The value is cached for a while.
302334 * The only way this can change is if user installs conda into this same environment.
303335 * Generally we expect that to happen the other way, the user creates a conda environment with conda in it.
@@ -338,30 +370,8 @@ export class CondaService implements ICondaService {
338370 if ( await this . fileSystem . fileExists ( condaPath2 ) ) {
339371 return condaPath2 ;
340372 }
341- }
342373
343- /**
344- * Is the given interpreter from conda?
345- */
346- private detectCondaEnvironment ( env : PythonEnvironment ) {
347- return (
348- env . envType === EnvironmentType . Conda
349- || ( env . displayName ? env . displayName : '' ) . toUpperCase ( ) . indexOf ( 'ANACONDA' ) >= 0
350- || ( env . companyDisplayName ? env . companyDisplayName : '' ) . toUpperCase ( ) . indexOf ( 'ANACONDA' ) >= 0
351- || ( env . companyDisplayName ? env . companyDisplayName : '' ) . toUpperCase ( ) . indexOf ( 'CONTINUUM' ) >= 0
352- ) ;
353- }
354-
355- /**
356- * Return the highest Python version from the given list.
357- */
358- private getLatestVersion ( interpreters : PythonEnvironment [ ] ) {
359- const sortedInterpreters = interpreters . slice ( ) ;
360- // tslint:disable-next-line:no-non-null-assertion
361- sortedInterpreters . sort ( ( a , b ) => ( a . version && b . version ? compare ( a . version . raw , b . version . raw ) : 0 ) ) ;
362- if ( sortedInterpreters . length > 0 ) {
363- return sortedInterpreters [ sortedInterpreters . length - 1 ] ;
364- }
374+ return undefined ;
365375 }
366376
367377 private addCondaPathChangedHandler ( ) {
@@ -396,8 +406,8 @@ export class CondaService implements ICondaService {
396406 }
397407 if ( this . platform . isWindows && this . registryLookupForConda ) {
398408 const interpreters = await this . registryLookupForConda . getInterpreters ( ) ;
399- const condaInterpreters = interpreters . filter ( this . detectCondaEnvironment ) ;
400- const condaInterpreter = this . getLatestVersion ( condaInterpreters ) ;
409+ const condaInterpreters = interpreters . filter ( CondaService . detectCondaEnvironment ) ;
410+ const condaInterpreter = CondaService . getLatestVersion ( condaInterpreters ) ;
401411 if ( condaInterpreter ) {
402412 const interpreterPath = await this . getCondaFileFromInterpreter (
403413 condaInterpreter . path ,
0 commit comments