Skip to content

Commit

Permalink
Fix for conda activation during testing (#24303)
Browse files Browse the repository at this point in the history
Potential fix for Re-activating Terminal

See:
#23922
#24286
  • Loading branch information
karthiknadig authored Oct 16, 2024
1 parent 8dd1e55 commit 07bb9fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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

0 comments on commit 07bb9fd

Please sign in to comment.