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 conda activation during testing #24295

Merged
merged 2 commits into from
Oct 14, 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
32 changes: 31 additions & 1 deletion src/client/pythonEnvironments/nativeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function toArch(a: string | undefined): Architecture {
}

function getLocation(nativeEnv: NativeEnvInfo, executable: string): string {
if (nativeEnv.kind === NativePythonEnvironmentKind.Conda) {
return nativeEnv.prefix ?? path.dirname(executable);
}

if (nativeEnv.executable) {
return nativeEnv.executable;
}
Expand Down Expand Up @@ -206,6 +210,32 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined {
};
}

function hasChanged(old: PythonEnvInfo, newEnv: PythonEnvInfo): boolean {
if (old.executable.filename !== newEnv.executable.filename) {
return true;
}
if (old.version.major !== newEnv.version.major) {
return true;
}
if (old.version.minor !== newEnv.version.minor) {
return true;
}
if (old.version.micro !== newEnv.version.micro) {
return true;
}
if (old.location !== newEnv.location) {
return true;
}
if (old.kind !== newEnv.kind) {
return true;
}
if (old.arch !== newEnv.arch) {
return true;
}

return false;
}

class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
private _onProgress: EventEmitter<ProgressNotificationEvent>;

Expand Down Expand Up @@ -354,7 +384,7 @@ 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) {
if (old && hasChanged(old, info)) {
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 });
Expand Down
2 changes: 1 addition & 1 deletion src/test/pythonEnvironments/nativeAPI.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ suite('Native Python API', () => {
mtime: -1,
},
kind: PythonEnvKind.Conda,
location: '/home/user/.conda/envs/conda_python/python',
location: '/home/user/.conda/envs/conda_python',
source: [],
name: 'conda_python',
type: PythonEnvType.Conda,
Expand Down
Loading