3
3
4
4
import { injectable } from 'inversify' ;
5
5
import * as vscode from 'vscode' ;
6
+ import { DiscoveryVariants } from '../common/experiments/groups' ;
6
7
import { getVersionString , parseVersion } from '../common/utils/version' ;
7
8
import {
8
9
CONDA_ENV_FILE_SERVICE ,
@@ -31,6 +32,7 @@ import { PythonEnvInfo, PythonEnvKind, PythonReleaseLevel } from './base/info';
31
32
import { buildEnvInfo } from './base/info/env' ;
32
33
import { ILocator , PythonLocatorQuery } from './base/locator' ;
33
34
import { getEnvs } from './base/locatorUtils' ;
35
+ import { inExperiment } from './common/externalDependencies' ;
34
36
import { PythonInterpreterLocatorService } from './discovery/locators' ;
35
37
import { InterpreterLocatorHelper } from './discovery/locators/helpers' ;
36
38
import { InterpreterLocatorProgressService } from './discovery/locators/progressService' ;
@@ -134,19 +136,20 @@ export interface IPythonEnvironments extends ILocator {}
134
136
135
137
@injectable ( )
136
138
class ComponentAdapter implements IComponentAdapter {
139
+ // this will be set based on experiment
140
+ private _enabled ?: boolean ;
141
+
137
142
constructor (
138
143
// The adapter only wraps one thing: the component API.
139
144
private readonly api : IPythonEnvironments ,
140
145
private readonly environmentsSecurity : IEnvironmentsSecurity ,
141
- // For now we effectively disable the component.
142
- private readonly enabled = false ,
143
146
) { }
144
147
145
148
// IInterpreterHelper
146
149
147
150
// A result of `undefined` means "Fall back to the old code!"
148
151
public async getInterpreterInformation ( pythonPath : string ) : Promise < undefined | Partial < PythonEnvironment > > {
149
- if ( ! this . enabled ) {
152
+ if ( ! ( await this . isEnabled ( ) ) ) {
150
153
return undefined ;
151
154
}
152
155
const env = await this . api . resolveEnv ( pythonPath ) ;
@@ -158,7 +161,7 @@ class ComponentAdapter implements IComponentAdapter {
158
161
159
162
// A result of `undefined` means "Fall back to the old code!"
160
163
public async isMacDefaultPythonPath ( pythonPath : string ) : Promise < boolean | undefined > {
161
- if ( ! this . enabled ) {
164
+ if ( ! ( await this . isEnabled ( ) ) ) {
162
165
return undefined ;
163
166
}
164
167
const env = await this . api . resolveEnv ( pythonPath ) ;
@@ -177,7 +180,7 @@ class ComponentAdapter implements IComponentAdapter {
177
180
pythonPath : string ,
178
181
resource ?: vscode . Uri ,
179
182
) : Promise < undefined | PythonEnvironment > {
180
- if ( ! this . enabled ) {
183
+ if ( ! ( await this . isEnabled ( ) ) ) {
181
184
return undefined ;
182
185
}
183
186
const info = buildEnvInfo ( { executable : pythonPath } ) ;
@@ -198,7 +201,7 @@ class ComponentAdapter implements IComponentAdapter {
198
201
199
202
// A result of `undefined` means "Fall back to the old code!"
200
203
public async isCondaEnvironment ( interpreterPath : string ) : Promise < boolean | undefined > {
201
- if ( ! this . enabled ) {
204
+ if ( ! ( await this . isEnabled ( ) ) ) {
202
205
return undefined ;
203
206
}
204
207
const env = await this . api . resolveEnv ( interpreterPath ) ;
@@ -210,7 +213,7 @@ class ComponentAdapter implements IComponentAdapter {
210
213
211
214
// A result of `undefined` means "Fall back to the old code!"
212
215
public async getCondaEnvironment ( interpreterPath : string ) : Promise < CondaEnvironmentInfo | undefined > {
213
- if ( ! this . enabled ) {
216
+ if ( ! ( await this . isEnabled ( ) ) ) {
214
217
return undefined ;
215
218
}
216
219
const env = await this . api . resolveEnv ( interpreterPath ) ;
@@ -231,25 +234,27 @@ class ComponentAdapter implements IComponentAdapter {
231
234
232
235
// A result of `undefined` means "Fall back to the old code!"
233
236
public async isWindowsStoreInterpreter ( pythonPath : string ) : Promise < boolean | undefined > {
234
- if ( ! this . enabled ) {
237
+ if ( ! ( await this . isEnabled ( ) ) ) {
235
238
return undefined ;
236
239
}
237
240
const env = await this . api . resolveEnv ( pythonPath ) ;
238
- if ( env === undefined ) {
239
- return undefined ;
241
+ if ( env ) {
242
+ return env . kind === PythonEnvKind . WindowsStore ;
240
243
}
241
- return env . kind === PythonEnvKind . WindowsStore ;
244
+ return undefined ;
242
245
}
243
246
244
247
// IInterpreterLocatorService
245
248
246
249
// A result of `undefined` means "Fall back to the old code!"
247
250
public get hasInterpreters ( ) : Promise < boolean | undefined > {
248
- if ( ! this . enabled ) {
249
- return Promise . resolve ( undefined ) ;
250
- }
251
- const iterator = this . api . iterEnvs ( ) ;
252
- return iterator . next ( ) . then ( ( res ) => ! res . done ) ;
251
+ return this . isEnabled ( ) . then ( ( enabled ) => {
252
+ if ( enabled ) {
253
+ const iterator = this . api . iterEnvs ( ) ;
254
+ return iterator . next ( ) . then ( ( res ) => ! res . done ) ;
255
+ }
256
+ return undefined ;
257
+ } ) ;
253
258
}
254
259
255
260
// A result of `undefined` means "Fall back to the old code!"
@@ -262,7 +267,7 @@ class ComponentAdapter implements IComponentAdapter {
262
267
// onSuggestion?: boolean;
263
268
// }
264
269
) : Promise < PythonEnvironment [ ] | undefined > {
265
- if ( ! this . enabled ) {
270
+ if ( ! ( await this . isEnabled ( ) ) ) {
266
271
return undefined ;
267
272
}
268
273
if ( options ?. onSuggestion ) {
@@ -285,6 +290,19 @@ class ComponentAdapter implements IComponentAdapter {
285
290
const envs = await getEnvs ( iterator ) ;
286
291
return envs . map ( convertEnvInfo ) ;
287
292
}
293
+
294
+ private async isEnabled ( ) : Promise < boolean > {
295
+ if ( this . _enabled === undefined ) {
296
+ this . _enabled = ( await Promise . all (
297
+ [
298
+ inExperiment ( DiscoveryVariants . discoverWithFileWatching ) ,
299
+ inExperiment ( DiscoveryVariants . discoveryWithoutFileWatching ) ,
300
+ ] ,
301
+ ) ) . includes ( true ) ;
302
+ }
303
+
304
+ return this . _enabled ;
305
+ }
288
306
}
289
307
290
308
export function registerLegacyDiscoveryForIOC (
0 commit comments