in Python/Product/VSInterpreters/Interpreter/PythonRegistrySearch.cs [138:241]
private VisualStudioInterpreterConfiguration TryReadConfiguration(
string company,
string tag,
RegistryKey tagKey,
RegistryKey installKey,
bool pythonCoreCompatibility,
InterpreterArchitecture assumedArch
) {
if (tagKey == null || installKey == null) {
return null;
}
string prefixPath, exePath, exewPath;
try {
prefixPath = PathUtils.NormalizePath(installKey.GetValue(null) as string);
exePath = PathUtils.NormalizePath(installKey.GetValue("ExecutablePath") as string);
exewPath = PathUtils.NormalizePath(installKey.GetValue("WindowedExecutablePath") as string);
} catch (ArgumentException ex) {
Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
return null;
}
if (pythonCoreCompatibility && !string.IsNullOrEmpty(prefixPath)) {
if (string.IsNullOrEmpty(exePath)) {
try {
exePath = PathUtils.GetAbsoluteFilePath(prefixPath, CPythonInterpreterFactoryConstants.ConsoleExecutable);
} catch (ArgumentException) {
}
}
if (string.IsNullOrEmpty(exewPath)) {
try {
exewPath = PathUtils.GetAbsoluteFilePath(prefixPath, CPythonInterpreterFactoryConstants.WindowsExecutable);
} catch (ArgumentException) {
}
}
}
var version = tagKey.GetValue("Version") as string;
if (pythonCoreCompatibility && string.IsNullOrEmpty(version) && tag.Length >= 3) {
version = tag.Substring(0, 3);
}
var sysVersionString = tagKey.GetValue("SysVersion") as string;
if (pythonCoreCompatibility && string.IsNullOrEmpty(sysVersionString) && tag.Length >= 3) {
sysVersionString = tag.Substring(0, 3);
}
if (string.IsNullOrEmpty(sysVersionString) || !Version.TryParse(sysVersionString, out var sysVersion)) {
sysVersion = new Version(0, 0);
}
if (sysVersion < new Version(3, 0)) {
return null; // Python 2.x is no longer supported.
}
try {
sysVersion.ToLanguageVersion();
} catch (InvalidOperationException) {
sysVersion = new Version(0, 0);
}
if (!InterpreterArchitecture.TryParse(tagKey.GetValue("SysArchitecture", null) as string, out var arch)) {
arch = assumedArch;
}
if (arch == InterpreterArchitecture.Unknown && File.Exists(exePath)) {
switch (NativeMethods.GetBinaryType(exePath)) {
case System.Reflection.ProcessorArchitecture.X86:
arch = InterpreterArchitecture.x86;
break;
case System.Reflection.ProcessorArchitecture.Amd64:
arch = InterpreterArchitecture.x64;
break;
}
}
if (pythonCoreCompatibility && sysVersion != null && sysVersion < new Version(3, 5) && arch == InterpreterArchitecture.x86) {
// Older versions of CPython did not include
// "-32" in their Tag, so we will add it here
// for uniqueness.
tag += "-32";
}
var pathVar = tagKey.GetValue("PathEnvironmentVariable") as string ??
CPythonInterpreterFactoryConstants.PathEnvironmentVariableName;
var id = CPythonInterpreterFactoryConstants.GetInterpreterId(company, tag);
var description = tagKey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(description)) {
description = pythonCoreCompatibility
? "Python {0}{1: ()}".FormatUI(version, arch)
: "{0} {1}".FormatUI(company, tag);
}
return new VisualStudioInterpreterConfiguration(
id,
description,
prefixPath,
exePath,
exewPath,
pathVar,
arch,
sysVersion
);
}