Skip to content

Commit 6608f9a

Browse files
authored
fix: let Python Envs extension handle missing python in conda envs (#24986)
fixes microsoft/vscode-python-environments#289
1 parent c3f601d commit 6608f9a

File tree

2 files changed

+3
-36
lines changed

2 files changed

+3
-36
lines changed

Diff for: src/client/envExt/api.legacy.ts

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { Terminal, Uri, WorkspaceFolder } from 'vscode';
4+
import { Terminal, Uri } from 'vscode';
55
import { getEnvExtApi, getEnvironment } from './api.internal';
66
import { EnvironmentType, PythonEnvironment as PythonEnvironmentLegacy } from '../pythonEnvironments/info';
77
import { PythonEnvironment, PythonTerminalOptions } from './types';
88
import { Architecture } from '../common/utils/platform';
99
import { parseVersion } from '../pythonEnvironments/base/info/pythonVersion';
1010
import { PythonEnvType } from '../pythonEnvironments/base/info';
11-
import { traceError, traceInfo } from '../logging';
11+
import { traceError } from '../logging';
1212
import { reportActiveInterpreterChanged } from '../environmentApi';
1313
import { getWorkspaceFolder, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis';
1414

@@ -120,36 +120,6 @@ export async function getActiveInterpreterLegacy(resource?: Uri): Promise<Python
120120
return pythonEnv ? toLegacyType(pythonEnv) : undefined;
121121
}
122122

123-
export async function ensureEnvironmentContainsPythonLegacy(
124-
pythonPath: string,
125-
workspaceFolder: WorkspaceFolder | undefined,
126-
callback: () => void,
127-
): Promise<void> {
128-
const api = await getEnvExtApi();
129-
const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath));
130-
if (!pythonEnv) {
131-
traceError(`EnvExt: Failed to resolve environment for ${pythonPath}`);
132-
return;
133-
}
134-
135-
const envType = toEnvironmentType(pythonEnv);
136-
if (envType === EnvironmentType.Conda) {
137-
const packages = await api.getPackages(pythonEnv);
138-
if (packages && packages.length > 0 && packages.some((pkg) => pkg.name.toLowerCase() === 'python')) {
139-
return;
140-
}
141-
traceInfo(`EnvExt: Python not found in ${envType} environment ${pythonPath}`);
142-
traceInfo(`EnvExt: Installing Python in ${envType} environment ${pythonPath}`);
143-
await api.installPackages(pythonEnv, ['python']);
144-
previousEnvMap.set(workspaceFolder?.uri.fsPath || '', pythonEnv);
145-
reportActiveInterpreterChanged({
146-
path: pythonPath,
147-
resource: workspaceFolder,
148-
});
149-
callback();
150-
}
151-
}
152-
153123
export async function setInterpreterLegacy(pythonPath: string, uri: Uri | undefined): Promise<void> {
154124
const api = await getEnvExtApi();
155125
const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath));

Diff for: src/client/interpreter/interpreterService.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
} from '../pythonEnvironments/base/locator';
4646
import { sleep } from '../common/utils/async';
4747
import { useEnvExtension } from '../envExt/api.internal';
48-
import { ensureEnvironmentContainsPythonLegacy, getActiveInterpreterLegacy } from '../envExt/api.legacy';
48+
import { getActiveInterpreterLegacy } from '../envExt/api.legacy';
4949

5050
type StoredPythonEnvironment = PythonEnvironment & { store?: boolean };
5151

@@ -290,9 +290,6 @@ export class InterpreterService implements Disposable, IInterpreterService {
290290
@cache(-1, true)
291291
private async ensureEnvironmentContainsPython(pythonPath: string, workspaceFolder: WorkspaceFolder | undefined) {
292292
if (useEnvExtension()) {
293-
await ensureEnvironmentContainsPythonLegacy(pythonPath, workspaceFolder, () => {
294-
this.didChangeInterpreterEmitter.fire(workspaceFolder?.uri);
295-
});
296293
return;
297294
}
298295

0 commit comments

Comments
 (0)