Skip to content

Commit 066b9c3

Browse files
authored
Fix location for native environments (microsoft#23851)
1 parent 7cc813d commit 066b9c3

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/client/pythonEnvironments/nativeAPI.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ function toArch(a: string | undefined): Architecture {
4848
}
4949
}
5050

51-
function getLocation(nativeEnv: NativeEnvInfo): string {
52-
if (nativeEnv.prefix) {
53-
return nativeEnv.prefix;
54-
}
51+
function getLocation(nativeEnv: NativeEnvInfo, executable: string): string {
5552
if (nativeEnv.executable) {
5653
return nativeEnv.executable;
5754
}
58-
// We should not get here: either prefix or executable should always be available
59-
return '';
55+
56+
if (nativeEnv.prefix) {
57+
return nativeEnv.prefix;
58+
}
59+
60+
// This is a path to a generated executable. Needed for backwards compatibility.
61+
return executable;
6062
}
6163

6264
function kindToShortString(kind: PythonEnvKind): string | undefined {
@@ -172,7 +174,7 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined {
172174
const executable = nativeEnv.executable ?? makeExecutablePath(nativeEnv.prefix);
173175
return {
174176
name,
175-
location: getLocation(nativeEnv),
177+
location: getLocation(nativeEnv, executable),
176178
kind,
177179
id: executable,
178180
executable: {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ suite('Native Python API', () => {
5252
distro: { org: '' },
5353
executable: { filename: '/usr/bin/python', sysPrefix: '/usr/bin', ctime: -1, mtime: -1 },
5454
kind: PythonEnvKind.System,
55-
location: '/usr/bin',
55+
location: '/usr/bin/python',
5656
source: [],
5757
name: 'basic_python',
5858
type: undefined,
@@ -103,7 +103,7 @@ suite('Native Python API', () => {
103103
mtime: -1,
104104
},
105105
kind: PythonEnvKind.Conda,
106-
location: '/home/user/.conda/envs/conda_python',
106+
location: '/home/user/.conda/envs/conda_python/python',
107107
source: [],
108108
name: 'conda_python',
109109
type: PythonEnvType.Conda,

0 commit comments

Comments
 (0)