diff --git a/src/client/pythonEnvironments/base/info/interpreter.ts b/src/client/pythonEnvironments/base/info/interpreter.ts index 26db361c8e65b..16d82d3280b50 100644 --- a/src/client/pythonEnvironments/base/info/interpreter.ts +++ b/src/client/pythonEnvironments/base/info/interpreter.ts @@ -46,6 +46,7 @@ type ShellExecFunc = (command: string, timeout: number) => Promise = E extends PythonEnvsChangedEvent ? PythonLocatorQuery : BasicPythonLocatorQuery; +type QueryForEvent = E extends PythonEnvsChangedEvent ? PythonLocatorQuery : BasicPythonLocatorQuery; /** * A single Python environment locator. diff --git a/src/client/pythonEnvironments/collection/environmentsReducer.ts b/src/client/pythonEnvironments/collection/environmentsReducer.ts index b4c80254a3f9c..b4f74ea416e79 100644 --- a/src/client/pythonEnvironments/collection/environmentsReducer.ts +++ b/src/client/pythonEnvironments/collection/environmentsReducer.ts @@ -7,7 +7,7 @@ import { traceVerbose } from '../../common/logger'; import { createDeferred } from '../../common/utils/async'; import { areSameEnvironment, PythonEnvInfo, PythonEnvKind } from '../base/info'; import { - ILocator, IPythonEnvsIterator, PythonEnvUpdatedEvent, QueryForEvent, + ILocator, IPythonEnvsIterator, PythonEnvUpdatedEvent, PythonLocatorQuery, } from '../base/locator'; import { PythonEnvsChangedEvent } from '../base/watcher'; @@ -47,7 +47,7 @@ export class PythonEnvsReducer implements ILocator { return this.parentLocator.resolveEnv(environment); } - public iterEnvs(query?: QueryForEvent): IPythonEnvsIterator { + public iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator { const didUpdate = new EventEmitter(); const incomingIterator = this.parentLocator.iterEnvs(query); const iterator: IPythonEnvsIterator = iterEnvsIterator(incomingIterator, didUpdate); diff --git a/src/client/pythonEnvironments/collection/environmentsResolver.ts b/src/client/pythonEnvironments/collection/environmentsResolver.ts index f35baf20bc2bc..286e0c33dbc83 100644 --- a/src/client/pythonEnvironments/collection/environmentsResolver.ts +++ b/src/client/pythonEnvironments/collection/environmentsResolver.ts @@ -7,23 +7,23 @@ import { traceVerbose } from '../../common/logger'; import { areSameEnvironment, PythonEnvInfo } from '../base/info'; import { InterpreterInformation } from '../base/info/interpreter'; import { - ILocator, IPythonEnvsIterator, PythonEnvUpdatedEvent, QueryForEvent, + ILocator, IPythonEnvsIterator, PythonEnvUpdatedEvent, PythonLocatorQuery, } from '../base/locator'; import { PythonEnvsChangedEvent } from '../base/watcher'; import { IEnvironmentInfoService } from '../info/environmentInfoService'; export class PythonEnvsResolver implements ILocator { public get onChanged(): Event { - return this.pythonEnvsReducer.onChanged; + return this.parentLocator.onChanged; } constructor( - private readonly pythonEnvsReducer: ILocator, + private readonly parentLocator: ILocator, private readonly environmentInfoService: IEnvironmentInfoService, ) {} public async resolveEnv(env: string | PythonEnvInfo): Promise { - const environment = await this.pythonEnvsReducer.resolveEnv(env); + const environment = await this.parentLocator.resolveEnv(env); if (!environment) { return undefined; } @@ -34,9 +34,9 @@ export class PythonEnvsResolver implements ILocator { return getResolvedEnv(interpreterInfo, environment); } - public iterEnvs(query?: QueryForEvent): IPythonEnvsIterator { + public iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator { const didUpdate = new EventEmitter(); - const incomingIterator = this.pythonEnvsReducer.iterEnvs(query); + const incomingIterator = this.parentLocator.iterEnvs(query); const iterator: IPythonEnvsIterator = this.iterEnvsIterator(incomingIterator, didUpdate); iterator.onUpdated = didUpdate.event; return iterator; diff --git a/src/test/pythonEnvironments/collection/environmentsResolver.unit.test.ts b/src/test/pythonEnvironments/collection/environmentsResolver.unit.test.ts index 4d6c740422c08..87d1483621ae6 100644 --- a/src/test/pythonEnvironments/collection/environmentsResolver.unit.test.ts +++ b/src/test/pythonEnvironments/collection/environmentsResolver.unit.test.ts @@ -58,10 +58,10 @@ suite('Environments Resolver', () => { const env3 = createEnv('env3', '2.7', PythonEnvKind.System, path.join('path', 'to', 'exec3')); const env4 = createEnv('env4', '3.9.0rc2', PythonEnvKind.Unknown, path.join('path', 'to', 'exec2')); const environmentsToBeIterated = [env1, env2, env3, env4]; - const pythonEnvReducer = new SimpleLocator(environmentsToBeIterated); - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const parentLocator = new SimpleLocator(environmentsToBeIterated); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const iterator = reducer.iterEnvs(); + const iterator = resolver.iterEnvs(); const envs = await getEnvs(iterator); assert.deepEqual(envs, environmentsToBeIterated); @@ -72,11 +72,11 @@ suite('Environments Resolver', () => { const env1 = createEnv('env1', '3.5.12b1', PythonEnvKind.Unknown, path.join('path', 'to', 'exec1')); const env2 = createEnv('env2', '3.8.1', PythonEnvKind.Unknown, path.join('path', 'to', 'exec2')); const environmentsToBeIterated = [env1, env2]; - const pythonEnvReducer = new SimpleLocator(environmentsToBeIterated); + const parentLocator = new SimpleLocator(environmentsToBeIterated); const onUpdatedEvents: (PythonEnvUpdatedEvent | null)[] = []; - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const iterator = reducer.iterEnvs(); // Act + const iterator = resolver.iterEnvs(); // Act // Assert let { onUpdated } = iterator; @@ -107,11 +107,11 @@ suite('Environments Resolver', () => { const updatedEnv = createEnv('env1', '3.8.1', PythonEnvKind.System, path.join('path', 'to', 'exec')); const environmentsToBeIterated = [env]; const didUpdate = new EventEmitter(); - const pythonEnvReducer = new SimpleLocator(environmentsToBeIterated, { onUpdated: didUpdate.event }); + const parentLocator = new SimpleLocator(environmentsToBeIterated, { onUpdated: didUpdate.event }); const onUpdatedEvents: (PythonEnvUpdatedEvent | null)[] = []; - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const iterator = reducer.iterEnvs(); // Act + const iterator = resolver.iterEnvs(); // Act // Assert let { onUpdated } = iterator; @@ -143,18 +143,18 @@ suite('Environments Resolver', () => { }); }); - test('onChanged fires iff onChanged from reducer fires', () => { - const pythonEnvReducer = new SimpleLocator([]); + test('onChanged fires iff onChanged from resolver fires', () => { + const parentLocator = new SimpleLocator([]); const event1: PythonEnvsChangedEvent = {}; const event2: PythonEnvsChangedEvent = { kind: PythonEnvKind.Unknown }; const expected = [event1, event2]; - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); const events: PythonEnvsChangedEvent[] = []; - reducer.onChanged((e) => events.push(e)); + resolver.onChanged((e) => events.push(e)); - pythonEnvReducer.fire(event1); - pythonEnvReducer.fire(event2); + parentLocator.fire(event1); + parentLocator.fire(event2); assert.deepEqual(events, expected); }); @@ -178,7 +178,7 @@ suite('Environments Resolver', () => { stubShellExec.restore(); }); - test('Calls into reducer to get resolved environment, then calls environnment service to resolve environment further and return it', async () => { + test('Calls into parent locator to get resolved environment, then calls environnment service to resolve environment further and return it', async () => { const env = createEnv('env1', '3.8', PythonEnvKind.Unknown, path.join('path', 'to', 'exec')); const resolvedEnvReturnedByReducer = createEnv( 'env1', @@ -186,22 +186,22 @@ suite('Environments Resolver', () => { PythonEnvKind.Conda, 'resolved/path/to/exec', ); - const pythonEnvReducer = new SimpleLocator([], { + const parentLocator = new SimpleLocator([], { resolve: async (e: PythonEnvInfo) => { if (e === env) { return resolvedEnvReturnedByReducer; } - throw new Error('Incorrect environment sent to the reducer'); + throw new Error('Incorrect environment sent to the resolver'); }, }); - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const expected = await reducer.resolveEnv(env); + const expected = await resolver.resolveEnv(env); assert.deepEqual(expected, createExpectedEnvInfo(resolvedEnvReturnedByReducer)); }); - test('If the reducer resolves environment, but fetching interpreter info returns undefined, return undefined', async () => { + test('If the parent locator resolves environment, but fetching interpreter info returns undefined, return undefined', async () => { stubShellExec.returns( new Promise>((_resolve, reject) => { reject(); @@ -214,29 +214,29 @@ suite('Environments Resolver', () => { PythonEnvKind.Conda, 'resolved/path/to/exec', ); - const pythonEnvReducer = new SimpleLocator([], { + const parentLocator = new SimpleLocator([], { resolve: async (e: PythonEnvInfo) => { if (e === env) { return resolvedEnvReturnedByReducer; } - throw new Error('Incorrect environment sent to the reducer'); + throw new Error('Incorrect environment sent to the resolver'); }, }); - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const expected = await reducer.resolveEnv(env); + const expected = await resolver.resolveEnv(env); assert.deepEqual(expected, undefined); }); - test("If the reducer isn't able to resolve environment, return undefined", async () => { + test("If the parent locator isn't able to resolve environment, return undefined", async () => { const env = createEnv('env', '3.8', PythonEnvKind.Unknown, path.join('path', 'to', 'exec')); - const pythonEnvReducer = new SimpleLocator([], { + const parentLocator = new SimpleLocator([], { resolve: async () => undefined, }); - const reducer = new PythonEnvsResolver(pythonEnvReducer, new EnvironmentInfoService()); + const resolver = new PythonEnvsResolver(parentLocator, new EnvironmentInfoService()); - const expected = await reducer.resolveEnv(env); + const expected = await resolver.resolveEnv(env); assert.deepEqual(expected, undefined); });