Skip to content
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
3 changes: 3 additions & 0 deletions src/common/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export namespace CondaStrings {
export const condaMissingPythonNoFix = l10n.t(
'No Python found in the selected conda environment. Please select another environment or install Python manually.',
);
export const condaCondaPrefixActive = l10n.t(
'CONDA_PREFIX is set for this VS Code session. Selection saved for new terminals only.',
);
}

export namespace PyenvStrings {
Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,9 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
}
const envVar = shellEnv.value;
if (envVar) {
if (envVar['VIRTUAL_ENV']) {
const envPath = normalizeShellPath(envVar['VIRTUAL_ENV'], e.terminal.state.shell);
const envVarPath = envVar['VIRTUAL_ENV'] || envVar['CONDA_PREFIX'];
if (envVarPath) {
const envPath = normalizeShellPath(envVarPath, e.terminal.state.shell);
const env = await api.resolveEnvironment(Uri.file(envPath));
if (env) {
monitoredTerminals.set(e.terminal, env);
Expand Down
12 changes: 11 additions & 1 deletion src/managers/conda/condaEnvManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CondaStrings } from '../../common/localize';
import { traceError } from '../../common/logging';
import { createDeferred, Deferred } from '../../common/utils/deferred';
import { normalizePath } from '../../common/utils/pathUtils';
import { showErrorMessage, withProgress } from '../../common/window.apis';
import { showErrorMessage, showInformationMessage, withProgress } from '../../common/window.apis';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { CondaSourcingStatus } from './condaSourcingUtils';
import {
Expand Down Expand Up @@ -289,6 +289,16 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
const folder = this.api.getPythonProject(scope);
const fsPath = folder?.uri?.fsPath ?? scope.fsPath;
if (fsPath) {
// Notify user if CONDA_PREFIX is set and they're trying to select a different environment
if (process.env.CONDA_PREFIX && checkedEnv) {
const condaPrefixPath = process.env.CONDA_PREFIX;
const selectedPath = checkedEnv.environmentPath.fsPath;
// Only show notification if they selected a different environment
if (condaPrefixPath !== selectedPath) {
showInformationMessage(CondaStrings.condaCondaPrefixActive);
}
}

const normalizedFsPath = normalizePath(fsPath);
if (checkedEnv) {
this.fsPathToEnv.set(normalizedFsPath, checkedEnv);
Expand Down
4 changes: 4 additions & 0 deletions src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export function getCondaPathSetting(): string | undefined {
}

export async function getCondaForWorkspace(fsPath: string): Promise<string | undefined> {
if (process.env.CONDA_PREFIX) {
return process.env.CONDA_PREFIX;
}

const state = await getWorkspacePersistentState();
const data: { [key: string]: string } | undefined = await state.get(CONDA_WORKSPACE_KEY);
if (data) {
Expand Down
Loading