Skip to content

Commit 082d69b

Browse files
authored
Fix where non-virtual env was treated as a virtualenv (#2616)
Fixes #1351
1 parent 6c05fae commit 082d69b

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/client/interpreter/locators/services/currentPathService.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { IProcessServiceFactory } from '../../../common/process/types';
66
import { IConfigurationService } from '../../../common/types';
77
import { IServiceContainer } from '../../../ioc/types';
88
import { IInterpreterHelper, InterpreterType, PythonInterpreter } from '../../contracts';
9-
import { IVirtualEnvironmentManager } from '../../virtualEnvs/types';
109
import { CacheableLocatorService } from './cacheableLocatorService';
1110

1211
/**
@@ -20,7 +19,6 @@ export class CurrentPathService extends CacheableLocatorService {
2019
private readonly fs: IFileSystem;
2120

2221
public constructor(
23-
@inject(IVirtualEnvironmentManager) private virtualEnvMgr: IVirtualEnvironmentManager,
2422
@inject(IInterpreterHelper) private helper: IInterpreterHelper,
2523
@inject(IProcessServiceFactory) private readonly processServiceFactory: IProcessServiceFactory,
2624
@inject(IServiceContainer) serviceContainer: IServiceContainer
@@ -60,28 +58,23 @@ export class CurrentPathService extends CacheableLocatorService {
6058
.then(listOfInterpreters => _.flatten(listOfInterpreters))
6159
.then(interpreters => interpreters.filter(item => item.length > 0))
6260
// tslint:disable-next-line:promise-function-async
63-
.then(interpreters => Promise.all(interpreters.map(interpreter => this.getInterpreterDetails(interpreter, resource))))
61+
.then(interpreters => Promise.all(interpreters.map(interpreter => this.getInterpreterDetails(interpreter))))
6462
.then(interpreters => interpreters.filter(item => !!item).map(item => item!));
6563
}
6664

6765
/**
6866
* Return the information about the identified interpreter binary.
6967
*/
70-
private async getInterpreterDetails(interpreter: string, resource?: Uri): Promise<PythonInterpreter | undefined> {
71-
return Promise.all([
72-
this.helper.getInterpreterInformation(interpreter),
73-
this.virtualEnvMgr.getEnvironmentName(interpreter, resource),
74-
this.virtualEnvMgr.getEnvironmentType(interpreter, resource)
75-
]).
76-
then(([details, virtualEnvName, type]) => {
68+
private async getInterpreterDetails(interpreter: string): Promise<PythonInterpreter | undefined> {
69+
return this.helper.getInterpreterInformation(interpreter)
70+
.then(details => {
7771
if (!details) {
7872
return;
7973
}
8074
return {
8175
...(details as PythonInterpreter),
82-
envName: virtualEnvName,
8376
path: interpreter,
84-
type: type ? type : InterpreterType.Unknown
77+
type: details.type ? details.type : InterpreterType.Unknown
8578
};
8679
});
8780
}

src/test/interpreters/currentPathService.unit.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@ suite('Interpreters CurrentPath Service', () => {
4949
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPersistentStateFactory), TypeMoq.It.isAny())).returns(() => persistentStateFactory.object);
5050
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService), TypeMoq.It.isAny())).returns(() => configurationService.object);
5151

52-
currentPathService = new CurrentPathService(virtualEnvironmentManager.object, interpreterHelper.object, procServiceFactory.object, serviceContainer.object);
52+
currentPathService = new CurrentPathService(interpreterHelper.object, procServiceFactory.object, serviceContainer.object);
5353
});
5454

5555
test('Interpreters that do not exist on the file system are not excluded from the list', async () => {
5656
// Specific test for 1305
5757
const version = 'mockVersion';
58-
const envName = 'mockEnvName';
5958
interpreterHelper.setup(v => v.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ version }));
60-
virtualEnvironmentManager.setup(v => v.getEnvironmentName(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(envName));
61-
virtualEnvironmentManager.setup(v => v.getEnvironmentType(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(InterpreterType.VirtualEnv));
6259

6360
const execArgs = ['-c', 'import sys;print(sys.executable)'];
6461
pythonSettings.setup(p => p.pythonPath).returns(() => 'root:Python');
@@ -75,8 +72,9 @@ suite('Interpreters CurrentPath Service', () => {
7572
const interpreters = await currentPathService.getInterpreters();
7673
processService.verifyAll();
7774
fileSystem.verifyAll();
75+
7876
expect(interpreters).to.be.of.length(2);
79-
expect(interpreters).to.deep.include({ version, envName, path: 'c:/root:python', type: InterpreterType.VirtualEnv });
80-
expect(interpreters).to.deep.include({ version, envName, path: 'c:/python3', type: InterpreterType.VirtualEnv });
77+
expect(interpreters).to.deep.include({ version, path: 'c:/root:python', type: InterpreterType.Unknown });
78+
expect(interpreters).to.deep.include({ version, path: 'c:/python3', type: InterpreterType.Unknown });
8179
});
8280
});

0 commit comments

Comments
 (0)