Skip to content

Commit ad3fb29

Browse files
author
Kartik Raj
authored
Use environment path instead of interpreter path to uniquely identify conda envs (#18770)
1 parent 7931c94 commit ad3fb29

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/client/interpreter/configuration/interpreterSelector/interpreterSelector.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify';
77
import { Disposable, Uri } from 'vscode';
88
import { arePathsSame } from '../../../common/platform/fs-paths';
99
import { IPathUtils, Resource } from '../../../common/types';
10-
import { PythonEnvironment } from '../../../pythonEnvironments/info';
10+
import { EnvironmentType, PythonEnvironment } from '../../../pythonEnvironments/info';
1111
import { IInterpreterService } from '../../contracts';
1212
import { IInterpreterComparer, IInterpreterQuickPickItem, IInterpreterSelector } from '../types';
1313

@@ -40,17 +40,22 @@ export class InterpreterSelector implements IInterpreterSelector {
4040
}
4141

4242
public suggestionToQuickPickItem(
43-
suggestion: PythonEnvironment,
43+
interpreter: PythonEnvironment,
4444
workspaceUri?: Uri,
4545
useDetailedName = false,
4646
): IInterpreterQuickPickItem {
47-
const detail = this.pathUtils.getDisplayName(suggestion.path, workspaceUri ? workspaceUri.fsPath : undefined);
48-
const cachedPrefix = suggestion.cachedEntry ? '(cached) ' : '';
47+
const detail = this.pathUtils.getDisplayName(
48+
interpreter.envType === EnvironmentType.Conda && interpreter.envPath
49+
? interpreter.envPath
50+
: interpreter.path,
51+
workspaceUri ? workspaceUri.fsPath : undefined,
52+
);
53+
const cachedPrefix = interpreter.cachedEntry ? '(cached) ' : '';
4954
return {
50-
label: (useDetailedName ? suggestion.detailedDisplayName : suggestion.displayName) || 'Python',
55+
label: (useDetailedName ? interpreter.detailedDisplayName : interpreter.displayName) || 'Python',
5156
description: `${cachedPrefix}${detail}`,
52-
path: suggestion.path,
53-
interpreter: suggestion,
57+
path: interpreter.path,
58+
interpreter,
5459
};
5560
}
5661

src/test/configuration/interpreterSelector/interpreterSelector.unit.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ class InterpreterQuickPickItem implements IInterpreterQuickPickItem {
4040

4141
public interpreter = ({} as unknown) as PythonEnvironment;
4242

43-
constructor(l: string, p: string) {
43+
constructor(l: string, p: string, d?: string) {
4444
this.path = p;
4545
this.label = l;
46+
this.description = d ?? p;
4647
}
4748
}
4849

@@ -85,6 +86,7 @@ suite('Interpreters - selector', () => {
8586
{ displayName: '2 (virtualenv)', path: 'c:/path2/path2', envType: EnvironmentType.VirtualEnv },
8687
{ displayName: '3', path: 'c:/path2/path2', envType: EnvironmentType.Unknown },
8788
{ displayName: '4', path: 'c:/path4/path4', envType: EnvironmentType.Conda },
89+
{ displayName: '5', path: 'c:/path5/path', envPath: 'c:/path5', envType: EnvironmentType.Conda },
8890
].map((item) => ({ ...info, ...item }));
8991
interpreterService
9092
.setup((x) => x.getAllInterpreters(TypeMoq.It.isAny()))
@@ -99,19 +101,25 @@ suite('Interpreters - selector', () => {
99101
new InterpreterQuickPickItem('2 (virtualenv)', 'c:/path2/path2'),
100102
new InterpreterQuickPickItem('3', 'c:/path2/path2'),
101103
new InterpreterQuickPickItem('4', 'c:/path4/path4'),
104+
new InterpreterQuickPickItem('5', 'c:/path5/path', 'c:/path5'),
102105
];
103106

104107
assert.strictEqual(actual.length, expected.length, 'Suggestion lengths are different.');
105108
for (let i = 0; i < expected.length; i += 1) {
106109
assert.strictEqual(
107110
actual[i].label,
108111
expected[i].label,
109-
`Suggestion label is different at ${i}: exected '${expected[i].label}', found '${actual[i].label}'.`,
112+
`Suggestion label is different at ${i}: expected '${expected[i].label}', found '${actual[i].label}'.`,
110113
);
111114
assert.strictEqual(
112115
actual[i].path,
113116
expected[i].path,
114-
`Suggestion path is different at ${i}: exected '${expected[i].path}', found '${actual[i].path}'.`,
117+
`Suggestion path is different at ${i}: expected '${expected[i].path}', found '${actual[i].path}'.`,
118+
);
119+
assert.strictEqual(
120+
actual[i].description,
121+
expected[i].description,
122+
`Suggestion description is different at ${i}: expected '${expected[i].description}', found '${actual[i].description}'.`,
115123
);
116124
}
117125
});
@@ -183,12 +191,12 @@ suite('Interpreters - selector', () => {
183191
assert.strictEqual(
184192
result[i].label,
185193
expected[i].label,
186-
`Suggestion label is different at ${i}: exected '${expected[i].label}', found '${result[i].label}'.`,
194+
`Suggestion label is different at ${i}: expected '${expected[i].label}', found '${result[i].label}'.`,
187195
);
188196
assert.strictEqual(
189197
result[i].path,
190198
expected[i].path,
191-
`Suggestion path is different at ${i}: exected '${expected[i].path}', found '${result[i].path}'.`,
199+
`Suggestion path is different at ${i}: expected '${expected[i].path}', found '${result[i].path}'.`,
192200
);
193201
}
194202
});

0 commit comments

Comments
 (0)