Skip to content

Commit 25fd710

Browse files
author
Kartik Raj
authored
Update the initialization of the PythonEnvInfoCache to pass in a function that checks for env info completeness (#14446)
* Update the initialization of the PythonEnvInfoCache to pass in a function that checks for env info completeness * Update interface
1 parent 20349f2 commit 25fd710

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/client/pythonEnvironments/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CachingLocator } from './base/locators/composite/cachingLocator';
1010
import { PythonEnvsChangedEvent } from './base/watcher';
1111
import { getGlobalPersistentStore } from './common/externalDependencies';
1212
import { ExtensionLocators, WorkspaceLocators } from './discovery/locators';
13+
import { EnvironmentInfoService } from './info/environmentInfoService';
1314
import { registerForIOC } from './legacyIOC';
1415

1516
/**
@@ -53,9 +54,9 @@ export class PythonEnvironments implements ILocator {
5354
export function createAPI(): [PythonEnvironments, () => void] {
5455
const [locators, activateLocators] = initLocators();
5556

56-
// Update this to pass in an actual function that checks for env info completeness.
57+
const envInfoService = new EnvironmentInfoService();
5758
const envsCache = new PythonEnvInfoCache(
58-
() => true, // "isComplete"
59+
(env: PythonEnvInfo) => envInfoService.isInfoProvided(env.executable.filename), // "isComplete"
5960
() => {
6061
const storage = getGlobalPersistentStore<PythonEnvInfo[]>('PYTHON_ENV_INFO_CACHE');
6162
return {

src/client/pythonEnvironments/info/environmentInfoService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface IEnvironmentInfoService {
1919
interpreterPath: string,
2020
priority?: EnvironmentInfoServiceQueuePriority
2121
): Promise<InterpreterInformation | undefined>;
22+
isInfoProvided(interpreterPath: string): boolean;
2223
}
2324

2425
async function buildEnvironmentInfo(interpreterPath: string): Promise<InterpreterInformation | undefined> {
@@ -70,4 +71,9 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
7071
return r;
7172
});
7273
}
74+
75+
public isInfoProvided(interpreterPath: string): boolean {
76+
const result = this.cache.get(interpreterPath);
77+
return !!(result && result.completed);
78+
}
7379
}

src/test/pythonEnvironments/info/environmentInfoService.functional.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,38 @@ suite('Environment Info Service', () => {
9191
});
9292
assert.ok(stubShellExec.calledOnce);
9393
});
94+
95+
test('isInfoProvided() returns true for items already processed', async () => {
96+
const envService = new EnvironmentInfoService();
97+
let result: boolean;
98+
const promises: Promise<InterpreterInformation | undefined>[] = [];
99+
const path1 = 'any-path1';
100+
const path2 = 'any-path2';
101+
102+
promises.push(envService.getEnvironmentInfo(path1));
103+
promises.push(envService.getEnvironmentInfo(path2));
104+
105+
await Promise.all(promises);
106+
result = envService.isInfoProvided(path1);
107+
assert.strictEqual(result, true);
108+
result = envService.isInfoProvided(path2);
109+
assert.strictEqual(result, true);
110+
});
111+
112+
test('isInfoProvided() returns false otherwise', async () => {
113+
const envService = new EnvironmentInfoService();
114+
const promises: Promise<InterpreterInformation | undefined>[] = [];
115+
const path1 = 'any-path1';
116+
const path2 = 'any-path2';
117+
118+
promises.push(envService.getEnvironmentInfo(path1));
119+
promises.push(envService.getEnvironmentInfo(path2));
120+
121+
let result = envService.isInfoProvided(path1);
122+
assert.strictEqual(result, false);
123+
result = envService.isInfoProvided(path2);
124+
assert.strictEqual(result, false);
125+
result = envService.isInfoProvided('some-random-path');
126+
assert.strictEqual(result, false);
127+
});
94128
});

0 commit comments

Comments
 (0)