@@ -32,14 +32,17 @@ import { IServiceManager } from '../ioc/types';
32
32
import { PythonEnvInfo , PythonEnvKind , PythonReleaseLevel } from './base/info' ;
33
33
import { buildEnvInfo } from './base/info/env' ;
34
34
import { ILocator , PythonLocatorQuery } from './base/locator' ;
35
+ import { isMacDefaultPythonPath } from './base/locators/lowLevel/macDefaultLocator' ;
35
36
import { getEnvs } from './base/locatorUtils' ;
37
+ import { getEnvironmentDirFromPath } from './common/commonUtils' ;
36
38
import { inExperiment } from './common/externalDependencies' ;
37
39
import { PythonInterpreterLocatorService } from './discovery/locators' ;
38
40
import { InterpreterLocatorHelper } from './discovery/locators/helpers' ;
39
41
import { InterpreterLocatorProgressService } from './discovery/locators/progressService' ;
40
42
import { CondaEnvironmentInfo } from './discovery/locators/services/conda' ;
41
43
import { CondaEnvFileService } from './discovery/locators/services/condaEnvFileService' ;
42
44
import { CondaEnvService } from './discovery/locators/services/condaEnvService' ;
45
+ import { isCondaEnvironment } from './discovery/locators/services/condaLocator' ;
43
46
import { CondaService } from './discovery/locators/services/condaService' ;
44
47
import { CurrentPathService , PythonInPathCommandProvider } from './discovery/locators/services/currentPathService' ;
45
48
import {
@@ -54,6 +57,7 @@ import { PipEnvService } from './discovery/locators/services/pipEnvService';
54
57
import { PipEnvServiceHelper } from './discovery/locators/services/pipEnvServiceHelper' ;
55
58
import { WindowsRegistryService } from './discovery/locators/services/windowsRegistryService' ;
56
59
import { WindowsStoreInterpreter } from './discovery/locators/services/windowsStoreInterpreter' ;
60
+ import { isWindowsStoreEnvironment } from './discovery/locators/services/windowsStoreLocator' ;
57
61
import {
58
62
WorkspaceVirtualEnvironmentsSearchPathProvider ,
59
63
WorkspaceVirtualEnvService ,
@@ -189,11 +193,11 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
189
193
if ( ! this . enabled ) {
190
194
return undefined ;
191
195
}
192
- const env = await this . api . resolveEnv ( pythonPath ) ;
193
- if ( env === undefined ) {
194
- return undefined ;
195
- }
196
- return env . kind === PythonEnvKind . MacDefault ;
196
+ // While `ComponentAdapter` represents how the component would be used in the rest of the
197
+ // extension, we cheat here for the sake of performance. This is not a problem because when
198
+ // we start using the component's public API directly we will be dealing with `PythonEnvInfo`
199
+ // instead of just `pythonPath`.
200
+ return isMacDefaultPythonPath ( pythonPath ) ;
197
201
}
198
202
199
203
// IInterpreterService
@@ -229,30 +233,30 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
229
233
if ( ! this . enabled ) {
230
234
return undefined ;
231
235
}
232
- const env = await this . api . resolveEnv ( interpreterPath ) ;
233
- if ( env === undefined ) {
234
- return undefined ;
235
- }
236
- return env . kind === PythonEnvKind . Conda ;
236
+ // While `ComponentAdapter` represents how the component would be used in the rest of the
237
+ // extension, we cheat here for the sake of performance. This is not a problem because when
238
+ // we start using the component's public API directly we will be dealing with `PythonEnvInfo`
239
+ // instead of just `pythonPath`.
240
+ return isCondaEnvironment ( interpreterPath ) ;
237
241
}
238
242
239
243
// A result of `undefined` means "Fall back to the old code!"
240
244
public async getCondaEnvironment ( interpreterPath : string ) : Promise < CondaEnvironmentInfo | undefined > {
241
245
if ( ! this . enabled ) {
242
246
return undefined ;
243
247
}
244
- const env = await this . api . resolveEnv ( interpreterPath ) ;
245
- if ( env === undefined ) {
246
- return undefined ;
247
- }
248
- if ( env . kind !== PythonEnvKind . Conda ) {
248
+ if ( ! ( await isCondaEnvironment ( interpreterPath ) ) ) {
249
249
return undefined ;
250
250
}
251
- if ( env . name !== '' ) {
252
- return { name : env . name , path : '' } ;
253
- }
251
+ // For Conda we assume we don't set name for environments if they're prefix conda environments, similarly
252
+ // we don't have 'path' set if they're non-prefix conda environments.
253
+ // So we don't have a helper function yet to give us a conda env's name (if it has one). So for
254
+ // now we always set `path` (and never `name`). Once we have such a helper we will use it.
255
+ // tslint:disable-next-line:no-suspicious-comment
256
+ // TODO: Expose these two properties via a helper in the Conda locator on a temporary basis.
257
+ const location = getEnvironmentDirFromPath ( interpreterPath ) ;
254
258
// else
255
- return { name : '' , path : env . location } ;
259
+ return { name : '' , path : location } ;
256
260
}
257
261
258
262
// IWindowsStoreInterpreter
@@ -262,11 +266,9 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
262
266
if ( ! this . enabled ) {
263
267
return undefined ;
264
268
}
265
- const env = await this . api . resolveEnv ( pythonPath ) ;
266
- if ( env ) {
267
- return env . kind === PythonEnvKind . WindowsStore ;
268
- }
269
- return undefined ;
269
+ // Eventually we won't be calling 'isWindowsStoreInterpreter' in the component adapter, so we won't
270
+ // need to use 'isWindowsStoreEnvironment' directly here. This is just a temporary implementation.
271
+ return isWindowsStoreEnvironment ( pythonPath ) ;
270
272
}
271
273
272
274
// IInterpreterLocatorService
0 commit comments