OLD | NEW |
(Empty) | |
| 1 import sys |
| 2 |
| 3 try: |
| 4 import distutils.msvc9compiler |
| 5 except ImportError: |
| 6 pass |
| 7 |
| 8 unpatched = dict() |
| 9 |
| 10 def patch_for_specialized_compiler(): |
| 11 """ |
| 12 Patch functions in distutils.msvc9compiler to use the standalone compiler |
| 13 build for Python (Windows only). Fall back to original behavior when the |
| 14 standalone compiler is not available. |
| 15 """ |
| 16 if 'distutils' not in globals(): |
| 17 # The module isn't available to be patched |
| 18 return |
| 19 |
| 20 if unpatched: |
| 21 # Already patched |
| 22 return |
| 23 |
| 24 unpatched.update(vars(distutils.msvc9compiler)) |
| 25 |
| 26 distutils.msvc9compiler.find_vcvarsall = find_vcvarsall |
| 27 distutils.msvc9compiler.query_vcvarsall = query_vcvarsall |
| 28 |
| 29 def find_vcvarsall(version): |
| 30 Reg = distutils.msvc9compiler.Reg |
| 31 VC_BASE = r'Software\%sMicrosoft\DevDiv\VCForPython\%0.1f' |
| 32 try: |
| 33 # Per-user installs register the compiler path here |
| 34 productdir = Reg.get_value(VC_BASE % ('', version), "installdir") |
| 35 except KeyError: |
| 36 try: |
| 37 # All-user installs on a 64-bit system register here |
| 38 productdir = Reg.get_value(VC_BASE % ('Wow6432Node\\', version), "in
stalldir") |
| 39 except KeyError: |
| 40 productdir = None |
| 41 |
| 42 if productdir: |
| 43 import os |
| 44 vcvarsall = os.path.join(productdir, "vcvarsall.bat") |
| 45 if os.path.isfile(vcvarsall): |
| 46 return vcvarsall |
| 47 |
| 48 return unpatched['find_vcvarsall'](version) |
| 49 |
| 50 def query_vcvarsall(version, *args, **kwargs): |
| 51 try: |
| 52 return unpatched['query_vcvarsall'](version, *args, **kwargs) |
| 53 except distutils.errors.DistutilsPlatformError: |
| 54 exc = sys.exc_info()[1] |
| 55 if exc and "vcvarsall.bat" in exc.args[0]: |
| 56 message = 'Microsoft Visual C++ %0.1f is required (%s).' % (version,
exc.args[0]) |
| 57 if int(version) == 9: |
| 58 # This redirection link is maintained by Microsoft. |
| 59 # Contact vspython@microsoft.com if it needs updating. |
| 60 raise distutils.errors.DistutilsPlatformError( |
| 61 message + ' Get it from http://aka.ms/vcpython27' |
| 62 ) |
| 63 raise distutils.errors.DistutilsPlatformError(message) |
| 64 raise |
OLD | NEW |