Skip to content

Commit b0c556f

Browse files
authored
Merge branch 'main' into bold-unicorn
2 parents 76aca52 + cc45070 commit b0c556f

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/common/localize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export namespace VenvManagerStrings {
9999
export const noEnvClickToCreate = l10n.t('No environment found, click to create');
100100
export const noEnvFound = l10n.t('No Python environments found.');
101101
export const createEnvironment = l10n.t('Create Environment');
102+
export const venvVirtualEnvActive = l10n.t(
103+
'VIRTUAL_ENV is set for this VS Code session. Selection saved for new terminals only.',
104+
);
102105

103106
export const venvName = l10n.t('Enter a name for the virtual environment');
104107
export const venvNameErrorEmpty = l10n.t('Name cannot be empty');

src/managers/builtin/venvManager.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import { PYTHON_EXTENSION_ID } from '../../common/constants';
3232
import { VenvManagerStrings } from '../../common/localize';
3333
import { traceError, traceWarn } from '../../common/logging';
3434
import { createDeferred, Deferred } from '../../common/utils/deferred';
35-
import { showErrorMessage, withProgress } from '../../common/window.apis';
35+
import { normalizePath } from '../../common/utils/pathUtils';
36+
import { showErrorMessage, showInformationMessage, withProgress } from '../../common/window.apis';
3637
import { findParentIfFile } from '../../features/envCommands';
3738
import { NativePythonFinder } from '../common/nativePythonFinder';
3839
import { getLatest, shortVersion, sortEnvironments } from '../common/utils';
@@ -403,6 +404,16 @@ export class VenvManager implements EnvironmentManager {
403404
return;
404405
}
405406

407+
// Notify user if VIRTUAL_ENV is set and they're trying to select a different environment
408+
if (process.env.VIRTUAL_ENV && environment) {
409+
const virtualEnvPath = process.env.VIRTUAL_ENV;
410+
const selectedPath = environment.sysPrefix;
411+
// Only show notification if they selected a different environment
412+
if (virtualEnvPath !== selectedPath) {
413+
showInformationMessage(VenvManagerStrings.venvVirtualEnvActive);
414+
}
415+
}
416+
406417
const before = this.fsPathToEnv.get(pw.uri.fsPath);
407418
if (environment) {
408419
this.fsPathToEnv.set(pw.uri.fsPath, environment);
@@ -561,7 +572,7 @@ export class VenvManager implements EnvironmentManager {
561572
this.fsPathToEnv.clear();
562573

563574
const sorted = sortEnvironments(this.collection);
564-
const projectPaths = this.api.getPythonProjects().map((p) => path.normalize(p.uri.fsPath));
575+
const projectPaths = this.api.getPythonProjects().map((p) => normalizePath(p.uri.fsPath));
565576
const events: (() => void)[] = [];
566577
// Iterates through all workspace projects
567578
for (const p of projectPaths) {
@@ -600,7 +611,7 @@ export class VenvManager implements EnvironmentManager {
600611
// Search through all known environments (e) and check if any are associated with the current project path. If so, add that environment and path in the map.
601612
const found = sorted.find((e) => {
602613
const t = this.api.getPythonProject(e.environmentPath)?.uri.fsPath;
603-
return t && path.normalize(t) === p;
614+
return t && normalizePath(t) === p;
604615
});
605616
if (found) {
606617
this.fsPathToEnv.set(p, found);
@@ -615,11 +626,15 @@ export class VenvManager implements EnvironmentManager {
615626
* Finds a PythonEnvironment in the given collection (or all environments) that matches the provided file system path. O(e) where e = environments.len
616627
*/
617628
private findEnvironmentByPath(fsPath: string, collection?: PythonEnvironment[]): PythonEnvironment | undefined {
618-
const normalized = path.normalize(fsPath);
629+
const normalized = normalizePath(fsPath);
619630
const envs = collection ?? this.collection;
620631
return envs.find((e) => {
621-
const n = path.normalize(e.environmentPath.fsPath);
622-
return n === normalized || path.dirname(n) === normalized || path.dirname(path.dirname(n)) === normalized;
632+
const n = normalizePath(e.environmentPath.fsPath);
633+
return (
634+
n === normalized ||
635+
normalizePath(path.dirname(e.environmentPath.fsPath)) === normalized ||
636+
normalizePath(path.dirname(path.dirname(e.environmentPath.fsPath))) === normalized
637+
);
623638
});
624639
}
625640

0 commit comments

Comments
 (0)