From f29c258e240773b1a658391f3830d1c9bd170dd2 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 22 Jul 2024 17:43:47 -0700 Subject: [PATCH] Fix `location` for native environments (#23851) --- src/client/pythonEnvironments/nativeAPI.ts | 16 +++++++++------- .../pythonEnvironments/nativeAPI.unit.test.ts | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index d98f5d86406e2..dd49b5599906d 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -48,15 +48,17 @@ function toArch(a: string | undefined): Architecture { } } -function getLocation(nativeEnv: NativeEnvInfo): string { - if (nativeEnv.prefix) { - return nativeEnv.prefix; - } +function getLocation(nativeEnv: NativeEnvInfo, executable: string): string { if (nativeEnv.executable) { return nativeEnv.executable; } - // We should not get here: either prefix or executable should always be available - return ''; + + if (nativeEnv.prefix) { + return nativeEnv.prefix; + } + + // This is a path to a generated executable. Needed for backwards compatibility. + return executable; } function kindToShortString(kind: PythonEnvKind): string | undefined { @@ -172,7 +174,7 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined { const executable = nativeEnv.executable ?? makeExecutablePath(nativeEnv.prefix); return { name, - location: getLocation(nativeEnv), + location: getLocation(nativeEnv, executable), kind, id: executable, executable: { diff --git a/src/test/pythonEnvironments/nativeAPI.unit.test.ts b/src/test/pythonEnvironments/nativeAPI.unit.test.ts index 2f122d850280f..c6c684e2b4e54 100644 --- a/src/test/pythonEnvironments/nativeAPI.unit.test.ts +++ b/src/test/pythonEnvironments/nativeAPI.unit.test.ts @@ -52,7 +52,7 @@ suite('Native Python API', () => { distro: { org: '' }, executable: { filename: '/usr/bin/python', sysPrefix: '/usr/bin', ctime: -1, mtime: -1 }, kind: PythonEnvKind.System, - location: '/usr/bin', + location: '/usr/bin/python', source: [], name: 'basic_python', type: undefined, @@ -103,7 +103,7 @@ suite('Native Python API', () => { mtime: -1, }, kind: PythonEnvKind.Conda, - location: '/home/user/.conda/envs/conda_python', + location: '/home/user/.conda/envs/conda_python/python', source: [], name: 'conda_python', type: PythonEnvType.Conda,