Skip to content
Merged
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
22 changes: 15 additions & 7 deletions src/managers/builtin/sysPythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import {
ResolveEnvironmentContext,
SetEnvironmentScope,
} from '../../api';
import { refreshPythons, resolveSystemPythonEnvironmentPath } from './utils';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { SysManagerStrings } from '../../common/localize';
import { createDeferred, Deferred } from '../../common/utils/deferred';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { getLatest } from '../common/utils';
import { SysManagerStrings } from '../../common/localize';
import {
setSystemEnvForWorkspace,
setSystemEnvForGlobal,
clearSystemEnvCache,
getSystemEnvForGlobal,
getSystemEnvForWorkspace,
setSystemEnvForGlobal,
setSystemEnvForWorkspace,
setSystemEnvForWorkspaces,
} from './cache';
import { refreshPythons, resolveSystemPythonEnvironmentPath } from './utils';

export class SysPythonManager implements EnvironmentManager {
private collection: PythonEnvironment[] = [];
Expand Down Expand Up @@ -86,6 +86,7 @@ export class SysPythonManager implements EnvironmentManager {
async () => {
const discard = this.collection.map((c) => c);

// hit here is fine...
this.collection = await refreshPythons(hardRefresh, this.nativeFinder, this.api, this.log, this);
await this.loadEnvMap();

Expand Down Expand Up @@ -198,13 +199,20 @@ export class SysPythonManager implements EnvironmentManager {
// This environment is unknown. Resolve it.
const resolved = await resolveSystemPythonEnvironmentPath(context.fsPath, this.nativeFinder, this.api, this);
if (resolved) {
// HERE IT GOT TOO MANY

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comments here and on 89

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops thank you- will remove it in a new PR

// This is just like finding a new environment or creating a new one.
// Add it to collection, and trigger the added event.

// For all other env types we need to ensure that the environment is of the type managed by the manager.
// But System is a exception, this is the last resort for resolving. So we don't need to check.
// We will just add it and treat it as a non-activatable environment.
this.collection.push(resolved);
const exists = this.collection.some(
(e) => e.environmentPath.toString() === resolved.environmentPath.toString(),
);
if (!exists) {
// only add it if it is not already in the collection to avoid duplicates
this.collection.push(resolved);
}
this._onDidChangeEnvironments.fire([{ environment: resolved, kind: EnvironmentChangeKind.add }]);
}

Expand All @@ -216,7 +224,7 @@ export class SysPythonManager implements EnvironmentManager {
}

private findEnvironmentByPath(fsPath: string): PythonEnvironment | undefined {
const normalized = path.normalize(fsPath);
const normalized = path.normalize(fsPath); // /opt/homebrew/bin/python3.12
return this.collection.find((e) => {
const n = path.normalize(e.environmentPath.fsPath);
return n === normalized || path.dirname(n) === normalized || path.dirname(path.dirname(n)) === normalized;
Expand Down