8000 Fix for duplication of python envs (#24321) · microsoft/vscode-python@40b29bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 40b29bf

Browse files
authored
Fix for duplication of python envs (#24321)
Fixes #24318
1 parent e7860a5 commit 40b29bf

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/client/pythonEnvironments/nativeAPI.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,12 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
384384
const info = toPythonEnvInfo(native);
385385
if (info) {
386386
const old = this._envs.find((item) => item.executable.filename === info.executable.filename);
387-
if (old && hasChanged(old, info)) {
387+
if (old) {
388388
this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename);
389389
this._envs.push(info);
390-
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });
390+
if (hasChanged(old, info)) {
391+
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });
392+
}
391393
} else {
392394
this._envs.push(info);
393395
this._onChanged.fire({ type: FileChangeType.Created, new: info, searchLocation });

src/test/pythonEnvironments/nativeAPI.unit.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,27 @@ suite('Native Python API', () => {
239239
assert.deepEqual(actual, [expectedConda1]);
240240
});
241241

242+
test('Ensure no duplication on resolve', async () => {
243+
mockFinder
244+
.setup((f) => f.refresh())
245+
.returns(() => {
246+
async function* generator() {
247+
yield* [conda1];
248+
}
249+
return generator();
250+
})
251+
.verifiable(typemoq.Times.once());
252+
mockFinder
253+
.setup((f) => f.resolve(typemoq.It.isAny()))
254+
.returns(() => Promise.resolve(conda))
255+
.verifiable(typemoq.Times.once());
256+
257+
await api.triggerRefresh();
258+
await api.resolveEnv('/home/user/.conda/envs/conda_python/python');
259+
const actual = api.getEnvs();
260+
assert.deepEqual(actual, [expectedConda1]);
261+
});
262+
242263
test('Conda environment with no python', async () => {
243264
mockFinder
244265
.setup((f) => f.refresh())

0 commit comments

Comments
 (0)
0