Skip to content

Commit 9006449

Browse files
committed
support CONDA_PREFIX pre-set
1 parent 0ada7cc commit 9006449

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/common/localize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export namespace CondaStrings {
168168
export const condaMissingPythonNoFix = l10n.t(
169169
'No Python found in the selected conda environment. Please select another environment or install Python manually.',
170170
);
171+
export const condaCondaPrefixActive = l10n.t(
172+
'CONDA_PREFIX is set for this VS Code session. Selection saved for new terminals only.',
173+
);
171174
}
172175

173176
export namespace PyenvStrings {

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
494494
}
495495
const envVar = shellEnv.value;
496496
if (envVar) {
497-
if (envVar['VIRTUAL_ENV']) {
498-
const envPath = normalizeShellPath(envVar['VIRTUAL_ENV'], e.terminal.state.shell);
497+
const envVarPath = envVar['VIRTUAL_ENV'] || envVar['CONDA_PREFIX'];
498+
if (envVarPath) {
499+
const envPath = normalizeShellPath(envVarPath, e.terminal.state.shell);
499500
const env = await api.resolveEnvironment(Uri.file(envPath));
500501
if (env) {
501502
monitoredTerminals.set(e.terminal, env);

src/managers/conda/condaEnvManager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { CondaStrings } from '../../common/localize';
2323
import { traceError } from '../../common/logging';
2424
import { createDeferred, Deferred } from '../../common/utils/deferred';
2525
import { normalizePath } from '../../common/utils/pathUtils';
26-
import { showErrorMessage, withProgress } from '../../common/window.apis';
26+
import { showErrorMessage, showInformationMessage, withProgress } from '../../common/window.apis';
2727
import { NativePythonFinder } from '../common/nativePythonFinder';
2828
import { CondaSourcingStatus } from './condaSourcingUtils';
2929
import {
@@ -289,6 +289,16 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
289289
const folder = this.api.getPythonProject(scope);
290290
const fsPath = folder?.uri?.fsPath ?? scope.fsPath;
291291
if (fsPath) {
292+
// Notify user if CONDA_PREFIX is set and they're trying to select a different environment
293+
if (process.env.CONDA_PREFIX && checkedEnv) {
294+
const condaPrefixPath = process.env.CONDA_PREFIX;
295+
const selectedPath = checkedEnv.environmentPath.fsPath;
296+
// Only show notification if they selected a different environment
297+
if (condaPrefixPath !== selectedPath) {
298+
showInformationMessage(CondaStrings.condaCondaPrefixActive);
299+
}
300+
}
301+
292302
const normalizedFsPath = normalizePath(fsPath);
293303
if (checkedEnv) {
294304
this.fsPathToEnv.set(normalizedFsPath, checkedEnv);

src/managers/conda/condaUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export function getCondaPathSetting(): string | undefined {
8282
}
8383

8484
export async function getCondaForWorkspace(fsPath: string): Promise<string | undefined> {
85+
if (process.env.CONDA_PREFIX) {
86+
return process.env.CONDA_PREFIX;
87+
}
88+
8589
const state = await getWorkspacePersistentState();
8690
const data: { [key: string]: string } | undefined = await state.get(CONDA_WORKSPACE_KEY);
8791
if (data) {

0 commit comments

Comments
 (0)