Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for duplication of python envs #24321

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading