You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 rivejä
2.1 KiB

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