Skip to content

Commit 80af3fa

Browse files
authored
Give preference to python exec info over registry (#2566)
Fixes #2563 Fix - Give preference to bitness information retrieved from Python Interpreter (via Python code), over what's been retrieved from Win Registry.
1 parent efc2878 commit 80af3fa

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

news/2 Fixes/2563.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Give preference to bitness information retrieved from Python interpreter over what's been retrieved from Windows Registry.

src/client/interpreter/interpreterService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
127127

128128
let fileHash = await this.fs.getFileHash(pythonPath).catch(() => '');
129129
fileHash = fileHash ? fileHash : '';
130-
const store = this.persistentStateFactory.createGlobalPersistentState<PythonInterpreter & { fileHash: string }>(`${pythonPath}.interpreter.details.v1`, undefined, EXPITY_DURATION);
130+
const store = this.persistentStateFactory.createGlobalPersistentState<PythonInterpreter & { fileHash: string }>(`${pythonPath}.interpreter.details.v2`, undefined, EXPITY_DURATION);
131131
if (store.value && fileHash && store.value.fileHash === fileHash) {
132132
return store.value;
133133
}

src/client/interpreter/locators/services/windowsRegistryService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export class WindowsRegistryService extends CacheableLocatorService {
129129
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
130130
return {
131131
...(details as PythonInterpreter),
132-
architecture: arch,
133132
path: executablePath,
134133
version,
135134
companyDisplayName: interpreterInfo.companyDisplayName,

src/test/interpreters/windowsRegistryService.unit.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const environmentsPath = path.join(__dirname, '..', '..', '..', 'src', 'test', '
1414
// tslint:disable-next-line:max-func-body-length
1515
suite('Interpreters from Windows Registry (unit)', () => {
1616
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
17+
let interpreterHelper: TypeMoq.IMock<IInterpreterHelper>;
1718
setup(() => {
1819
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
1920
const stateFactory = TypeMoq.Mock.ofType<IPersistentStateFactory>();
20-
const interpreterHelper = TypeMoq.Mock.ofType<IInterpreterHelper>();
21+
interpreterHelper = TypeMoq.Mock.ofType<IInterpreterHelper>();
2122
const pathUtils = TypeMoq.Mock.ofType<IPathUtils>();
2223
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPersistentStateFactory))).returns(() => stateFactory.object);
2324
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IInterpreterHelper))).returns(() => interpreterHelper.object);
@@ -57,6 +58,9 @@ suite('Interpreters from Windows Registry (unit)', () => {
5758
const registry = new MockRegistry(registryKeys, registryValues);
5859
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
5960

61+
interpreterHelper.reset();
62+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
63+
6064
const interpreters = await winRegistry.getInterpreters();
6165

6266
assert.equal(interpreters.length, 1, 'Incorrect number of entries');
@@ -76,6 +80,9 @@ suite('Interpreters from Windows Registry (unit)', () => {
7680
const registry = new MockRegistry(registryKeys, registryValues);
7781
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
7882

83+
interpreterHelper.reset();
84+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
85+
7986
const interpreters = await winRegistry.getInterpreters();
8087

8188
assert.equal(interpreters.length, 1, 'Incorrect number of entries');
@@ -109,6 +116,8 @@ suite('Interpreters from Windows Registry (unit)', () => {
109116
];
110117
const registry = new MockRegistry(registryKeys, registryValues);
111118
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
119+
interpreterHelper.reset();
120+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
112121

113122
const interpreters = await winRegistry.getInterpreters();
114123

@@ -150,6 +159,8 @@ suite('Interpreters from Windows Registry (unit)', () => {
150159
];
151160
const registry = new MockRegistry(registryKeys, registryValues);
152161
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
162+
interpreterHelper.reset();
163+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
153164

154165
const interpreters = await winRegistry.getInterpreters();
155166

@@ -206,6 +217,8 @@ suite('Interpreters from Windows Registry (unit)', () => {
206217
];
207218
const registry = new MockRegistry(registryKeys, registryValues);
208219
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
220+
interpreterHelper.reset();
221+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
209222

210223
const interpreters = await winRegistry.getInterpreters();
211224

@@ -262,6 +275,8 @@ suite('Interpreters from Windows Registry (unit)', () => {
262275
];
263276
const registry = new MockRegistry(registryKeys, registryValues);
264277
const winRegistry = new WindowsRegistryService(registry, false, serviceContainer.object);
278+
interpreterHelper.reset();
279+
interpreterHelper.setup(h => h.getInterpreterInformation(TypeMoq.It.isAny())).returns(() => Promise.resolve({ architecture: Architecture.x86 }));
265280

266281
const interpreters = await winRegistry.getInterpreters();
267282

0 commit comments

Comments
 (0)