diff options
author | Jurko Gospodnetić <jurko.gospodnetic@pke.hr> | 2017-12-11 01:56:57 +0100 |
---|---|---|
committer | Bernat Gabor <bgabor8@bloomberg.net> | 2018-10-25 11:14:35 +0100 |
commit | 5fd620cab75d266a1364a2d4a37a1a6d757fc9e3 (patch) | |
tree | 6c19870c5d5c7ef0d9ca5914d5a6acaab531da6c | |
parent | af5711ca9346b265f196a9cf266cecda9bca5b91 (diff) | |
download | virtualenv-5fd620cab75d266a1364a2d4a37a1a6d757fc9e3.tar.gz |
update detecting Windows Python installations
- now correctly detects current user installation and not just
those installed at the system level
- for Python versions 3.5+ (which track 32-bit & 64-bit installations
separately), recognize version tags X.Y, X.Y-32 & X.Y-64 where X.Y
represents the 64-bit installation if available or 32-bit otherwise
-rwxr-xr-x | src/virtualenv.py | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/virtualenv.py b/src/virtualenv.py index e7e7111..8839343 100755 --- a/src/virtualenv.py +++ b/src/virtualenv.py @@ -85,33 +85,51 @@ else: import _winreg as winreg def get_installed_pythons(): - try: - python_core = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, - "Software\\Python\\PythonCore") - except WindowsError: - # No registered Python installations - return {} - i = 0 - versions = [] - while True: - try: - versions.append(winreg.EnumKey(python_core, i)) - i = i + 1 - except WindowsError: - break exes = dict() - for ver in versions: + # If both system and current user installations are found for a + # particular Python version, the current user one is used + for key in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER): try: - path = winreg.QueryValue(python_core, "%s\\InstallPath" % ver) + python_core = winreg.CreateKey(key, + "Software\\Python\\PythonCore") except WindowsError: + # No registered Python installations continue - exes[ver] = join(path, "python.exe") - - winreg.CloseKey(python_core) + i = 0 + while True: + try: + version = winreg.EnumKey(python_core, i) + i += 1 + try: + path = winreg.QueryValue(python_core, + "%s\\InstallPath" % version) + except WindowsError: + continue + exes[version] = join(path, "python.exe") + except WindowsError: + break + winreg.CloseKey(python_core) + + # For versions that track separate 32-bit (`X.Y-32`) & 64-bit (`X-Y`) + # installation registrations, add a `X.Y-64` version tag and make the + # extensionless `X.Y` version tag represent the 64-bit installation if + # available or 32-bit if it is not + updated = {} + for ver in exes: + if ver < '3.5': + continue + if ver.endswith('-32'): + base_ver = ver[:-3] + if base_ver not in exes: + updated[base_ver] = exes[ver] + else: + updated[ver + '-64'] = exes[ver] + exes.update(updated) # Add the major versions # Sort the keys, then repeatedly update the major version entry - # Last executable (i.e., highest version) wins with this approach + # Last executable (i.e., highest version) wins with this approach, + # 64-bit over 32-bit if both are found for ver in sorted(exes): exes[ver[0]] = exes[ver] |