Skip to content

Commit 9920c7f

Browse files
author
Eric Snow
authored
In PythonEnvsReducer.resolveEnv(), always fall back to the wrapped locator. (microsoft#15350)
fixes microsoft#15118
1 parent 36bb325 commit 9920c7f

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/client/pythonEnvironments/base/locators/composite/environmentsReducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export class PythonEnvsReducer implements ILocator {
2222

2323
public async resolveEnv(env: string | PythonEnvInfo): Promise<PythonEnvInfo | undefined> {
2424
const environments = await getEnvs(this.iterEnvs());
25-
const environment = environments.find((e) => areSameEnv(e, env));
25+
let environment: string | PythonEnvInfo | undefined = environments.find((e) => areSameEnv(e, env));
2626
if (!environment) {
27-
return undefined;
27+
// It isn't one we've reduced, but fall back
28+
// to the wrapped locator anyway.
29+
environment = env;
2830
}
2931
return this.parentLocator.resolveEnv(environment);
3032
}

src/test/pythonEnvironments/base/locators/composite/environmentsReducer.unit.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ suite('Python envs locator - Environments Reducer', () => {
248248
assert.deepEqual(resolved, expected);
249249
});
250250

251-
test("If the reducer isn't able to resolve environment, return undefined", async () => {
251+
test("If the reducer isn't able to resolve environment, fall back to the wrapped locator", async () => {
252252
const env1 = createNamedEnv('env', '3.8', PythonEnvKind.Conda, path.join('path', 'to', 'exec'));
253253
const env2 = createNamedEnv('env2', '2.7', PythonEnvKind.System, path.join('path', 'to', 'exec3'));
254254
const env3 = createNamedEnv('env', '3.8.1b1', PythonEnvKind.System, path.join('path', 'to', 'exec'));
@@ -257,20 +257,24 @@ suite('Python envs locator - Environments Reducer', () => {
257257
const env6 = createNamedEnv('env', '3.8.1', PythonEnvKind.Unknown, path.join('path', 'to', 'exec'));
258258
const environmentsToBeIterated = [env1, env2, env3, env4, env5, env6]; // env1 env3 env6 are same
259259

260-
const env136 = createNamedEnv('env', '3.8.1b1', PythonEnvKind.Conda, path.join('path', 'to', 'exec'));
260+
const filename1 = path.join('resolved', 'path', 'to', 'execNeverSeenBefore');
261+
const filename2 = path.join('resolved', 'path', 'to', 'execAlsoNeverSeenBefore');
262+
const expected = createNamedEnv('resolvedEnv', '3.8.1', PythonEnvKind.Conda, filename1);
261263
const parentLocator = new SimpleLocator(environmentsToBeIterated, {
262264
resolve: async (e: PythonEnvInfo) => {
263-
if (isEqual(e, env136)) {
264-
return createNamedEnv('resolvedEnv', '3.8.1', PythonEnvKind.Conda, 'resolved/path/to/exec');
265+
if (e.executable.filename === expected.executable.filename) {
266+
return expected;
265267
}
266-
throw new Error('Incorrect environment sent to the resolve');
268+
return undefined;
267269
},
268270
});
269271
const reducer = new PythonEnvsReducer(parentLocator);
270272

271-
const expected = await reducer.resolveEnv(path.join('path', 'to', 'execNeverSeenBefore'));
273+
const resolved1 = await reducer.resolveEnv(filename1);
274+
const resolved2 = await reducer.resolveEnv(filename2);
272275

273-
assert.deepEqual(expected, undefined);
276+
assert.deepEqual(resolved1, expected);
277+
assert.equal(resolved2, undefined);
274278
});
275279
});
276280
});

0 commit comments

Comments
 (0)