Skip to content

Commit e4cb306

Browse files
Copiloteleanorjboyd
andcommitted
Update environment picker to include full interpreter paths in descriptions
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent a988e69 commit e4cb306

2 files changed

Lines changed: 120 additions & 8 deletions

File tree

src/common/pickers/environments.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ export async function pickEnvironment(
157157
];
158158

159159
if (options?.recommended) {
160+
// Include interpreter path in description for recommended environment too
161+
const pathDescription = options.recommended.displayPath;
162+
const description = options.recommended.description && options.recommended.description.trim()
163+
? `${options.recommended.description} (${pathDescription})`
164+
: pathDescription;
165+
160166
items.push(
161167
{
162168
label: Common.recommended,
163169
kind: QuickPickItemKind.Separator,
164170
},
165171
{
166172
label: options.recommended.displayName,
167-
description: options.recommended.description,
173+
description: description,
168174
result: options.recommended,
169175
iconPath: getIconPath(options.recommended.iconPath),
170176
},
@@ -179,9 +185,15 @@ export async function pickEnvironment(
179185
const envs = await manager.getEnvironments('all');
180186
items.push(
181187
...envs.map((e) => {
188+
// Include interpreter path in description. If original description exists and is not empty, append path to it.
189+
const pathDescription = e.displayPath;
190+
const description = e.description && e.description.trim()
191+
? `${e.description} (${pathDescription})`
192+
: pathDescription;
193+
182194
return {
183195
label: e.displayName ?? e.name,
184-
description: e.description,
196+
description: description,
185197
result: e,
186198
manager: manager,
187199
iconPath: getIconPath(e.iconPath),
@@ -194,12 +206,20 @@ export async function pickEnvironment(
194206
}
195207

196208
export async function pickEnvironmentFrom(environments: PythonEnvironment[]): Promise<PythonEnvironment | undefined> {
197-
const items = environments.map((e) => ({
198-
label: e.displayName ?? e.name,
199-
description: e.description,
200-
e: e,
201-
iconPath: getIconPath(e.iconPath),
202-
}));
209+
const items = environments.map((e) => {
210+
// Include interpreter path in description. If original description exists and is not empty, append path to it.
211+
const pathDescription = e.displayPath;
212+
const description = e.description && e.description.trim()
213+
? `${e.description} (${pathDescription})`
214+
: pathDescription;
215+
216+
return {
217+
label: e.displayName ?? e.name,
218+
description: description,
219+
e: e,
220+
iconPath: getIconPath(e.iconPath),
221+
};
222+
});
203223
const selected = await showQuickPick(items, {
204224
placeHolder: Pickers.Environments.selectEnvironment,
205225
ignoreFocusOut: true,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import assert from 'node:assert';
5+
import { Uri } from 'vscode';
6+
import { PythonEnvironment } from '../../api';
7+
8+
/**
9+
* Test the logic used in environment pickers to include interpreter paths in descriptions
10+
*/
11+
suite('Environment Picker Description Logic', () => {
12+
const createMockEnvironment = (
13+
displayPath: string,
14+
description?: string,
15+
name: string = 'Python 3.9.0',
16+
): PythonEnvironment => ({
17+
envId: { id: 'test', managerId: 'test-manager' },
18+
name,
19+
displayName: name,
20+
displayPath,
21+
version: '3.9.0',
22+
environmentPath: Uri.file(displayPath),
23+
description,
24+
sysPrefix: '/path/to/prefix',
25+
execInfo: { run: { executable: displayPath } },
26+
});
27+
28+
suite('Description formatting with interpreter path', () => {
29+
test('should use displayPath as description when no original description exists', () => {
30+
const env = createMockEnvironment('/usr/local/bin/python');
31+
32+
// This is the logic from our updated picker
33+
const pathDescription = env.displayPath;
34+
const description = env.description && env.description.trim()
35+
? `${env.description} (${pathDescription})`
36+
: pathDescription;
37+
38+
assert.strictEqual(description, '/usr/local/bin/python');
39+
});
40+
41+
test('should append displayPath to existing description in parentheses', () => {
42+
const env = createMockEnvironment('/home/user/.venv/bin/python', 'Virtual Environment');
43+
44+
// This is the logic from our updated picker
45+
const pathDescription = env.displayPath;
46+
const description = env.description && env.description.trim()
47+
? `${env.description} (${pathDescription})`
48+
: pathDescription;
49+
50+
assert.strictEqual(description, 'Virtual Environment (/home/user/.venv/bin/python)');
51+
});
52+
53+
test('should handle complex paths correctly', () => {
54+
const complexPath = '/usr/local/anaconda3/envs/my-project-env/bin/python';
55+
const env = createMockEnvironment(complexPath, 'Conda Environment');
56+
57+
// This is the logic from our updated picker
58+
const pathDescription = env.displayPath;
59+
const description = env.description && env.description.trim()
60+
? `${env.description} (${pathDescription})`
61+
: pathDescription;
62+
63+
assert.strictEqual(description, `Conda Environment (${complexPath})`);
64+
});
65+
66+
test('should handle empty description correctly', () => {
67+
const env = createMockEnvironment('/opt/python/bin/python', '');
68+
69+
// This is the logic from our updated picker
70+
const pathDescription = env.displayPath;
71+
const description = env.description && env.description.trim()
72+
? `${env.description} (${pathDescription})`
73+
: pathDescription;
74+
75+
// Empty string should be treated like no description, so just use path
76+
assert.strictEqual(description, '/opt/python/bin/python');
77+
});
78+
79+
test('should handle Windows paths correctly', () => {
80+
const windowsPath = 'C:\\Python39\\python.exe';
81+
const env = createMockEnvironment(windowsPath, 'System Python');
82+
83+
// This is the logic from our updated picker
84+
const pathDescription = env.displayPath;
85+
const description = env.description && env.description.trim()
86+
? `${env.description} (${pathDescription})`
87+
: pathDescription;
88+
89+
assert.strictEqual(description, 'System Python (C:\\Python39\\python.exe)');
90+
});
91+
});
92+
});

0 commit comments

Comments
 (0)