Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c40af3

Browse files
authored
Fix interpreter display (microsoft#391)
* fixed microsoft#389 microsoft#390 * strip duplicate conda name from display
1 parent b0fb5c0 commit 8c40af3

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class CondaEnvService implements IInterpreterLocatorService {
5555
return;
5656
}
5757

58-
const versionWithoutCompanyName = this.stripCompanyName(version);
58+
const versionWithoutCompanyName = this.stripCondaDisplayName(this.stripCompanyName(version), condaDisplayName);
5959
const displayName = `${condaDisplayName} ${versionWithoutCompanyName}`.trim();
6060
// If it is an environment, hence suffix with env name.
6161
const interpreterDisplayName = env === info.default_prefix ? displayName : `${displayName} (${envName})`;
@@ -86,6 +86,18 @@ export class CondaEnvService implements IInterpreterLocatorService {
8686

8787
return startOfCompanyName > 0 ? content.substring(0, startOfCompanyName).trim() : content;
8888
}
89+
private stripCondaDisplayName(content: string, condaDisplayName: string) {
90+
// Strip company name from version.
91+
if (content.endsWith(condaDisplayName)) {
92+
let updatedContent = content.substr(0, content.indexOf(condaDisplayName)).trim();
93+
if (updatedContent.endsWith('::')) {
94+
updatedContent = updatedContent.substr(0, content.indexOf('::')).trim();
95+
}
96+
return updatedContent;
97+
} else {
98+
return content;
99+
}
100+
}
89101
private async getSuggestionsFromConda(): Promise<PythonInterpreter[]> {
90102
return this.condaLocator.getCondaFile()
91103
.then(async condaFile => {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Uri } from 'vscode';
66
import { Architecture, IRegistry, RegistryHive } from '../../../common/platform/types';
77
import { Is64Bit } from '../../../common/types';
88
import { IInterpreterLocatorService, InterpreterType, PythonInterpreter } from '../../contracts';
9+
import { AnacondaCompanyName, AnacondaCompanyNames } from './conda';
910

1011
// tslint:disable-next-line:variable-name
1112
const DefaultPythonExecutable = 'python.exe';
@@ -100,10 +101,11 @@ export class WindowsRegistryService implements IInterpreterLocatorService {
100101
this.registry.getValue(key, hive, arch, 'ExecutablePath'),
101102
// tslint:disable-next-line:no-non-null-assertion
102103
this.getInterpreterDisplayName(tagKey, companyKey, hive, arch),
103-
this.registry.getValue(tagKey, hive, arch, 'Version'),
104+
this.registry.getValue(tagKey, hive, arch, 'SysVersion'),
104105
this.getCompanyDisplayName(companyKey, hive, arch)
105106
])
106107
.then(([installedPath, executablePath, displayName, version, companyDisplayName]) => {
108+
companyDisplayName = AnacondaCompanyNames.indexOf(companyDisplayName) === -1 ? companyDisplayName : AnacondaCompanyName;
107109
// tslint:disable-next-line:prefer-type-cast
108110
return { installPath: installedPath, executablePath, displayName, version, companyDisplayName } as InterpreterInformation;
109111
});

src/test/interpreters/windowsRegistryService.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suite('Interpreters from Windows Registry', () => {
3636
{ key: '\\Software\\Python\\Company One', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Display Name for Company One', name: 'DisplayName' },
3737
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path1') },
3838
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path1', 'one.exe'), name: 'ExecutablePath' },
39-
{ key: '\\Software\\Python\\Company One\\Tag1', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'Version' },
39+
{ key: '\\Software\\Python\\Company One\\Tag1', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'SysVersion' },
4040
{ key: '\\Software\\Python\\Company One\\Tag1', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag1', name: 'DisplayName' }
4141
];
4242
const registry = new MockRegistry(registryKeys, registryValues);
@@ -119,14 +119,14 @@ suite('Interpreters from Windows Registry', () => {
119119
{ key: '\\Software\\Python\\Company One', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Display Name for Company One', name: 'DisplayName' },
120120
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path1') },
121121
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path1', 'python.exe'), name: 'ExecutablePath' },
122-
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2'), name: 'Version' },
122+
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2'), name: 'SysVersion' },
123123
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag1', name: 'DisplayName' },
124124

125125
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2') },
126126
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2', 'python.exe'), name: 'ExecutablePath' },
127127

128128
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path3') },
129-
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'Version' },
129+
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'SysVersion' },
130130

131131
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'numpy') },
132132
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag B', name: 'DisplayName' },
@@ -175,14 +175,14 @@ suite('Interpreters from Windows Registry', () => {
175175
{ key: '\\Software\\Python\\Company One', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Display Name for Company One', name: 'DisplayName' },
176176
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'numpy') },
177177
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'numpy', 'python.exe'), name: 'ExecutablePath' },
178-
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'Version' },
178+
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'SysVersion' },
179179
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag1', name: 'DisplayName' },
180180

181181
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'scipy') },
182182
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'scipy', 'python.exe'), name: 'ExecutablePath' },
183183

184184
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path1') },
185-
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'Version' },
185+
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'SysVersion' },
186186

187187
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2') },
188188
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag B', name: 'DisplayName' },
@@ -234,14 +234,14 @@ suite('Interpreters from Windows Registry', () => {
234234
{ key: '\\Software\\Python\\Company One', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Display Name for Company One', name: 'DisplayName' },
235235
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'numpy') },
236236
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'conda', 'envs', 'numpy', 'python.exe'), name: 'ExecutablePath' },
237-
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'Version' },
237+
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag1', name: 'SysVersion' },
238238
{ key: '\\Software\\Python\\Company One\\Tag1\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag1', name: 'DisplayName' },
239239

240240
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'non-existent-path', 'envs', 'scipy') },
241241
{ key: '\\Software\\Python\\Company One\\Tag2\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'non-existent-path', 'envs', 'scipy', 'python.exe'), name: 'ExecutablePath' },
242242

243243
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'non-existent-path') },
244-
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'Version' },
244+
{ key: '\\Software\\Python\\Company Two\\Tag A\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'Version.Tag A', name: 'SysVersion' },
245245

246246
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: path.join(environmentsPath, 'path2') },
247247
{ key: '\\Software\\Python\\Company Two\\Tag B\\InstallPath', hive: RegistryHive.HKCU, arch: Architecture.x86, value: 'DisplayName.Tag B', name: 'DisplayName' },

0 commit comments

Comments
 (0)