168 @type list of str (optional) |
168 @type list of str (optional) |
169 @return list of found interpreter executables |
169 @return list of found interpreter executables |
170 @rtype list of str |
170 @rtype list of str |
171 """ |
171 """ |
172 try: |
172 try: |
173 import winreg |
173 import winreg # noqa: I101, I103 |
174 except ImportError: |
174 except ImportError: |
175 import _winreg as winreg # __IGNORE_WARNING__ |
175 import _winreg as winreg # noqa: I101, I102 |
176 |
176 |
177 def getExePath(branch, access, versionStr): |
177 def getExePath(branch, access, versionStr): |
178 with contextlib.suppress(WindowsError, OSError): |
178 with contextlib.suppress(WindowsError, OSError): |
179 software = winreg.OpenKey(branch, "Software", 0, access) |
179 software = winreg.OpenKey(branch, "Software", 0, access) |
180 python = winreg.OpenKey(software, "Python", 0, access) |
180 python = winreg.OpenKey(software, "Python", 0, access) |
181 pcore = winreg.OpenKey(python, "PythonCore", 0, access) |
181 pcore = winreg.OpenKey(python, "PythonCore", 0, access) |
182 version = winreg.OpenKey(pcore, versionStr, 0, access) |
182 version = winreg.OpenKey(pcore, versionStr, 0, access) |
183 installpath = winreg.QueryValue(version, "InstallPath") |
183 installpath = winreg.QueryValue(version, "InstallPath") |
184 exe = os.path.join(installpath, "python.exe") |
184 exe = os.path.join(installpath, "python.exe") |
185 if os.access(exe, os.X_OK): |
185 if os.access(exe, os.X_OK): |
186 return exe |
186 return exe |
187 |
187 |
188 return None |
188 return None |
189 |
189 |
198 |
198 |
199 else: |
199 else: |
200 versionSuffixes = ["", "-32", "-64"] |
200 versionSuffixes = ["", "-32", "-64"] |
201 for minorVersion in minorVersions: |
201 for minorVersion in minorVersions: |
202 for versionSuffix in versionSuffixes: |
202 for versionSuffix in versionSuffixes: |
203 versionStr = "{0}.{1}{2}".format( |
203 versionStr = "{0}.{1}{2}".format("3", minorVersion, versionSuffix) |
204 "3", minorVersion, versionSuffix |
|
205 ) |
|
206 exePath = getExePath( |
204 exePath = getExePath( |
207 winreg.HKEY_CURRENT_USER, |
205 winreg.HKEY_CURRENT_USER, |
208 winreg.KEY_WOW64_32KEY | winreg.KEY_READ, |
206 winreg.KEY_WOW64_32KEY | winreg.KEY_READ, |
209 versionStr, |
207 versionStr, |
210 ) |
208 ) |