Skip to content

Commit 5ec0753

Browse files
author
Kartik Raj
authored
Ensure 64-bit interpreters are preferred over 32-bit when auto-selecting (#19043)
* Ensure 64-bit interpreters are preferred over 32-bit when auto-selecting * Fix bug * News
1 parent 49dfe9e commit 5ec0753

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

news/2 Fixes/19042.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure 64-bit interpreters are preferred over 32-bit when auto-selecting.

src/client/interpreter/configuration/environmentTypeComparer.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT License.
33

44
import { injectable, inject } from 'inversify';
5-
import { getArchitectureDisplayName } from '../../common/platform/registry';
65
import { Resource } from '../../common/types';
6+
import { Architecture } from '../../common/utils/platform';
77
import { isParentPath } from '../../pythonEnvironments/common/externalDependencies';
88
import { EnvironmentType, PythonEnvironment, virtualEnvTypes } from '../../pythonEnvironments/info';
99
import { PythonVersion } from '../../pythonEnvironments/info/pythonVersion';
@@ -111,7 +111,7 @@ function getSortName(info: PythonEnvironment, interpreterHelper: IInterpreterHel
111111
sortNameParts.push(info.version.raw);
112112
}
113113
if (info.architecture) {
114-
sortNameParts.push(getArchitectureDisplayName(info.architecture));
114+
sortNameParts.push(getArchitectureSortName(info.architecture));
115115
}
116116
if (info.companyDisplayName && info.companyDisplayName.length > 0) {
117117
sortNameParts.push(info.companyDisplayName.trim());
@@ -133,6 +133,18 @@ function getSortName(info: PythonEnvironment, interpreterHelper: IInterpreterHel
133133
return `${sortNameParts.join(' ')} ${envSuffix}`.trim();
134134
}
135135

136+
function getArchitectureSortName(arch?: Architecture) {
137+
// Strings are choosen keeping in mind that 64-bit gets preferred over 32-bit.
138+
switch (arch) {
139+
case Architecture.x64:
140+
return 'x64';
141+
case Architecture.x86:
142+
return 'x86';
143+
default:
144+
return '';
145+
}
146+
}
147+
136148
function isBaseCondaEnvironment(environment: PythonEnvironment): boolean {
137149
return (
138150
environment.envType === EnvironmentType.Conda &&

src/test/configuration/environmentTypeComparer.unit.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as assert from 'assert';
55
import * as path from 'path';
66
import * as sinon from 'sinon';
7+
import { Architecture } from '../../client/common/utils/platform';
78
import {
89
EnvironmentTypeComparer,
910
EnvLocationHeuristic,
@@ -218,6 +219,20 @@ suite('Environment sorting', () => {
218219
} as PythonEnvironment,
219220
expected: 1,
220221
},
222+
{
223+
title: 'If 2 global interpreters have the same Python version, they should be sorted by architecture',
224+
envA: {
225+
envType: EnvironmentType.Global,
226+
architecture: Architecture.x86,
227+
version: { major: 3, minor: 10, patch: 2 },
228+
} as PythonEnvironment,
229+
envB: {
230+
envType: EnvironmentType.Global,
231+
architecture: Architecture.x64,
232+
version: { major: 3, minor: 10, patch: 2 },
233+
} as PythonEnvironment,
234+
expected: 1,
235+
},
221236
];
222237

223238
testcases.forEach(({ title, envA, envB, expected }) => {

0 commit comments

Comments
 (0)