Skip to content

fix: let Python Envs extension handle missing python in conda envs #24986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions src/client/envExt/api.legacy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Terminal, Uri, WorkspaceFolder } from 'vscode';
import { Terminal, Uri } from 'vscode';
import { getEnvExtApi, getEnvironment } from './api.internal';
import { EnvironmentType, PythonEnvironment as PythonEnvironmentLegacy } from '../pythonEnvironments/info';
import { PythonEnvironment, PythonTerminalOptions } from './types';
import { Architecture } from '../common/utils/platform';
import { parseVersion } from '../pythonEnvironments/base/info/pythonVersion';
import { PythonEnvType } from '../pythonEnvironments/base/info';
import { traceError, traceInfo } from '../logging';
import { traceError } from '../logging';
import { reportActiveInterpreterChanged } from '../environmentApi';
import { getWorkspaceFolder, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis';

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

export async function ensureEnvironmentContainsPythonLegacy(
pythonPath: string,
workspaceFolder: WorkspaceFolder | undefined,
callback: () => void,
): Promise<void> {
const api = await getEnvExtApi();
const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath));
if (!pythonEnv) {
traceError(`EnvExt: Failed to resolve environment for ${pythonPath}`);
return;
}

const envType = toEnvironmentType(pythonEnv);
if (envType === EnvironmentType.Conda) {
const packages = await api.getPackages(pythonEnv);
if (packages && packages.length > 0 && packages.some((pkg) => pkg.name.toLowerCase() === 'python')) {
return;
}
traceInfo(`EnvExt: Python not found in ${envType} environment ${pythonPath}`);
traceInfo(`EnvExt: Installing Python in ${envType} environment ${pythonPath}`);
await api.installPackages(pythonEnv, ['python']);
previousEnvMap.set(workspaceFolder?.uri.fsPath || '', pythonEnv);
reportActiveInterpreterChanged({
path: pythonPath,
resource: workspaceFolder,
});
callback();
}
}

export async function setInterpreterLegacy(pythonPath: string, uri: Uri | undefined): Promise<void> {
const api = await getEnvExtApi();
const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath));
Expand Down
5 changes: 1 addition & 4 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from '../pythonEnvironments/base/locator';
import { sleep } from '../common/utils/async';
import { useEnvExtension } from '../envExt/api.internal';
import { ensureEnvironmentContainsPythonLegacy, getActiveInterpreterLegacy } from '../envExt/api.legacy';
import { getActiveInterpreterLegacy } from '../envExt/api.legacy';

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

Expand Down Expand Up @@ -290,9 +290,6 @@ export class InterpreterService implements Disposable, IInterpreterService {
@cache(-1, true)
private async ensureEnvironmentContainsPython(pythonPath: string, workspaceFolder: WorkspaceFolder | undefined) {
if (useEnvExtension()) {
await ensureEnvironmentContainsPythonLegacy(pythonPath, workspaceFolder, () => {
this.didChangeInterpreterEmitter.fire(workspaceFolder?.uri);
});
return;
}

Expand Down
Loading