Skip to content

Commit 96d4116

Browse files
committed
Fix for conda activation during testing (microsoft#24295)
1 parent f020e5c commit 96d4116

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/client/pythonEnvironments/nativeAPI.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function toArch(a: string | undefined): Architecture {
5555
}
5656

5757
function getLocation(nativeEnv: NativeEnvInfo, executable: string): string {
58+
if (nativeEnv.kind === NativePythonEnvironmentKind.Conda) {
59+
return nativeEnv.prefix ?? path.dirname(executable);
60+
}
61+
5862
if (nativeEnv.executable) {
5963
return nativeEnv.executable;
6064
}
@@ -206,6 +210,32 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined {
206210
};
207211
}
208212

213+
function hasChanged(old: PythonEnvInfo, newEnv: PythonEnvInfo): boolean {
214+
if (old.executable.filename !== newEnv.executable.filename) {
215+
return true;
216+
}
217+
if (old.version.major !== newEnv.version.major) {
218+
return true;
219+
}
220+
if (old.version.minor !== newEnv.version.minor) {
221+
return true;
222+
}
223+
if (old.version.micro !== newEnv.version.micro) {
224+
return true;
225+
}
226+
if (old.location !== newEnv.location) {
227+
return true;
228+
}
229+
if (old.kind !== newEnv.kind) {
230+
return true;
231+
}
232+
if (old.arch !== newEnv.arch) {
233+
return true;
234+
}
235+
236+
return false;
237+
}
238+
209239
class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
210240
private _onProgress: EventEmitter<ProgressNotificationEvent>;
211241

@@ -354,7 +384,7 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
354384
const info = toPythonEnvInfo(native);
355385
if (info) {
356386
const old = this._envs.find((item) => item.executable.filename === info.executable.filename);
357-
if (old) {
387+
if (old && hasChanged(old, info)) {
358388
this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename);
359389
this._envs.push(info);
360390
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ suite('Native Python API', () => {
108108
mtime: -1,
109109
},
110110
kind: PythonEnvKind.Conda,
111-
location: '/home/user/.conda/envs/conda_python/python',
111+
location: '/home/user/.conda/envs/conda_python',
112112
source: [],
113113
name: 'conda_python',
114114
type: PythonEnvType.Conda,

0 commit comments

Comments
 (0)