@@ -25,6 +25,7 @@ export class JupyterInterpreterService {
25
25
private _selectedInterpreter ?: PythonInterpreter ;
26
26
private _selectedInterpreterPath ?: string ;
27
27
private _onDidChangeInterpreter = new EventEmitter < PythonInterpreter > ( ) ;
28
+ private validateSavedInterpreterPromise : Promise < boolean > | undefined ;
28
29
public get onDidChangeInterpreter ( ) : Event < PythonInterpreter > {
29
30
return this . _onDidChangeInterpreter . event ;
30
31
}
@@ -38,6 +39,13 @@ export class JupyterInterpreterService {
38
39
private readonly interpreterConfiguration : JupyterInterpreterDependencyService ,
39
40
@inject ( IInterpreterService ) private readonly interpreterService : IInterpreterService
40
41
) { }
42
+ public async validateSavedInterpreter ( ) : Promise < boolean > {
43
+ if ( ! this . validateSavedInterpreterPromise ) {
44
+ this . validateSavedInterpreterPromise = this . validateSavedInterpreterImpl ( ) ;
45
+ }
46
+
47
+ return this . validateSavedInterpreterPromise ;
48
+ }
41
49
/**
42
50
* Gets the selected interpreter configured to run Jupyter.
43
51
*
@@ -65,7 +73,17 @@ export class JupyterInterpreterService {
65
73
return interpreter ;
66
74
}
67
75
68
- const pythonPath = this . _selectedInterpreterPath || this . interpreterSelectionState . selectedPythonPath ;
76
+ let pythonPath = this . _selectedInterpreterPath ;
77
+
78
+ if ( ! pythonPath && this . interpreterSelectionState . selectedPythonPath ) {
79
+ // On activate we kick off a check to see if the saved interpreter is still valid
80
+ // make sure that has completed before we actually use it as a valid interpreter
81
+ if ( await this . validateSavedInterpreter ( ) ) {
82
+ pythonPath = this . interpreterSelectionState . selectedPythonPath ;
83
+ }
84
+ }
85
+
86
+ // If nothing saved, then check our current interpreter to see if we can use it
69
87
if ( ! pythonPath ) {
70
88
// Check if current interpreter has all of the required dependencies.
71
89
// If yes, then use that.
@@ -183,4 +201,32 @@ export class JupyterInterpreterService {
183
201
this . interpreterSelectionState . updateSelectedPythonPath ( ( this . _selectedInterpreterPath = interpreter . path ) ) ;
184
202
sendTelemetryEvent ( Telemetry . SelectJupyterInterpreter , undefined , { result : 'selected' } ) ;
185
203
}
204
+
205
+ private async validateSavedInterpreterImpl ( ) : Promise < boolean > {
206
+ if ( ! this . interpreterSelectionState . selectedPythonPath ) {
207
+ // None set yet, so no need to check
208
+ return false ;
209
+ }
210
+
211
+ try {
212
+ const interpreterDetails = await this . interpreterService . getInterpreterDetails (
213
+ this . interpreterSelectionState . selectedPythonPath ,
214
+ undefined
215
+ ) ;
216
+
217
+ if ( interpreterDetails ) {
218
+ if ( await this . interpreterConfiguration . areDependenciesInstalled ( interpreterDetails , undefined ) ) {
219
+ // Our saved interpreter was found and has dependencies installed
220
+ return true ;
221
+ }
222
+ }
223
+ } catch ( _err ) {
224
+ traceInfo ( 'Saved Jupyter interpreter invalid' ) ;
225
+ }
226
+
227
+ // At this point we failed some aspect of our checks regarding our saved interpreter, so clear it out
228
+ this . _selectedInterpreter = undefined ;
229
+ this . interpreterSelectionState . updateSelectedPythonPath ( undefined ) ;
230
+ return false ;
231
+ }
186
232
}
0 commit comments