Skip to content

Commit

Permalink
Fix for duplication of python envs (microsoft#24321)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Oct 21, 2024
1 parent e7860a5 commit 40b29bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/client/pythonEnvironments/nativeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,12 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
const info = toPythonEnvInfo(native);
if (info) {
const old = this._envs.find((item) => item.executable.filename === info.executable.filename);
if (old && hasChanged(old, info)) {
if (old) {
this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename);
this._envs.push(info);
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });
if (hasChanged(old, info)) {
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });
}
} else {
this._envs.push(info);
this._onChanged.fire({ type: FileChangeType.Created, new: info, searchLocation });
Expand Down
21 changes: 21 additions & 0 deletions src/test/pythonEnvironments/nativeAPI.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ suite('Native Python API', () => {
assert.deepEqual(actual, [expectedConda1]);
});

test('Ensure no duplication on resolve', async () => {
mockFinder
.setup((f) => f.refresh())
.returns(() => {
async function* generator() {
yield* [conda1];
}
return generator();
})
.verifiable(typemoq.Times.once());
mockFinder
.setup((f) => f.resolve(typemoq.It.isAny()))
.returns(() => Promise.resolve(conda))
.verifiable(typemoq.Times.once());

await api.triggerRefresh();
await api.resolveEnv('/home/user/.conda/envs/conda_python/python');
const actual = api.getEnvs();
assert.deepEqual(actual, [expectedConda1]);
});

test('Conda environment with no python', async () => {
mockFinder
.setup((f) => f.refresh())
Expand Down

0 comments on commit 40b29bf

Please sign in to comment.