Skip to content

Commit 90802a0

Browse files
author
Kartik Raj
authored
Display problematic environments towards the end of the interpreters list (#19588)
1 parent ddd30b0 commit 90802a0

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/client/interpreter/configuration/environmentTypeComparer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export class EnvironmentTypeComparer implements IInterpreterComparer {
4141
* Always sort with newest version of Python first within each subgroup.
4242
*/
4343
public compare(a: PythonEnvironment, b: PythonEnvironment): number {
44+
if (isProblematicCondaEnvironment(a)) {
45+
return 1;
46+
}
47+
if (isProblematicCondaEnvironment(b)) {
48+
return -1;
49+
}
4450
// Check environment location.
4551
const envLocationComparison = compareEnvironmentLocation(a, b, this.workspaceFolderPath);
4652
if (envLocationComparison !== 0) {
@@ -84,6 +90,9 @@ export class EnvironmentTypeComparer implements IInterpreterComparer {
8490
// because we would have to add a way to match environments to a workspace.
8591
const workspaceUri = this.interpreterHelper.getActiveWorkspaceUri(resource);
8692
const filteredInterpreters = interpreters.filter((i) => {
93+
if (isProblematicCondaEnvironment(i)) {
94+
return false;
95+
}
8796
if (getEnvLocationHeuristic(i, workspaceUri?.folderUri.fsPath || '') === EnvLocationHeuristic.Local) {
8897
return true;
8998
}
@@ -152,6 +161,10 @@ function isBaseCondaEnvironment(environment: PythonEnvironment): boolean {
152161
);
153162
}
154163

164+
export function isProblematicCondaEnvironment(environment: PythonEnvironment): boolean {
165+
return environment.envType === EnvironmentType.Conda && environment.path === 'python';
166+
}
167+
155168
/**
156169
* Compare 2 Python versions in decending order, most recent one comes first.
157170
*/

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { EnvironmentType } from '../../../../pythonEnvironments/info';
2828
import { captureTelemetry, sendTelemetryEvent } from '../../../../telemetry';
2929
import { EventName } from '../../../../telemetry/constants';
3030
import { IInterpreterService, PythonEnvironmentsChangedEvent } from '../../../contracts';
31+
import { isProblematicCondaEnvironment } from '../../environmentTypeComparer';
3132
import {
3233
IInterpreterQuickPickItem,
3334
IInterpreterSelector,
@@ -354,11 +355,7 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
354355
this.setRecommendedItem(interpreterSuggestions, items, resource);
355356
// Add warning label to certain environments
356357
items.forEach((item, i) => {
357-
if (
358-
isInterpreterQuickPickItem(item) &&
359-
item.interpreter.path === 'python' &&
360-
item.interpreter.envType === EnvironmentType.Conda
361-
) {
358+
if (isInterpreterQuickPickItem(item) && isProblematicCondaEnvironment(item.interpreter)) {
362359
if (!items[i].label.includes(Octicons.Warning)) {
363360
items[i].label = `${Octicons.Warning} ${items[i].label}`;
364361
}

src/client/pythonEnvironments/base/locators/composite/resolverUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function resolveBasicEnv(env: BasicEnvInfo, useCache = false): Prom
6767

6868
function getSearchLocation(env: PythonEnvInfo): Uri | undefined {
6969
const folders = getWorkspaceFolders();
70-
const isRootedEnv = folders.some((f) => isParentPath(env.executable.filename, f));
70+
const isRootedEnv = folders.some((f) => isParentPath(env.executable.filename, f) || isParentPath(env.location, f));
7171
if (isRootedEnv) {
7272
// For environments inside roots, we need to set search location so they can be queried accordingly.
7373
// In certain usecases environment directory can itself be a root, for eg. `python -m venv .`.

src/test/configuration/environmentTypeComparer.unit.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ suite('Environment sorting', () => {
233233
} as PythonEnvironment,
234234
expected: 1,
235235
},
236+
{
237+
title: 'Problematic environments should come last',
238+
envA: {
239+
envType: EnvironmentType.Conda,
240+
envPath: path.join(workspacePath, '.venv'),
241+
path: 'python',
242+
} as PythonEnvironment,
243+
envB: {
244+
envType: EnvironmentType.System,
245+
version: { major: 3, minor: 10, patch: 2 },
246+
} as PythonEnvironment,
247+
expected: 1,
248+
},
236249
];
237250

238251
testcases.forEach(({ title, envA, envB, expected }) => {

0 commit comments

Comments
 (0)