/lib/galaxy/__init__.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 111 lines · 83 code · 14 blank · 14 comment · 41 complexity · 6ffb4c7f553be890403b1848aa3a48f9 MD5 · raw file

  1. """
  2. Galaxy root package -- this is a namespace package.
  3. """
  4. __import__( "pkg_resources" ).declare_namespace( __name__ )
  5. import os, sys, re
  6. from distutils.sysconfig import get_config_var, get_config_vars
  7. import pkg_resources
  8. # patch get_platform() for better ABI recognition
  9. def _get_build_platform():
  10. plat = pkg_resources._get_build_platform()
  11. if sys.version_info[:2] == ( 2, 5 ) and \
  12. ( ( os.uname()[-1] in ( 'x86_64', 'i386', 'ppc' ) and sys.platform == 'darwin' and os.path.abspath( sys.prefix ).startswith( '/System' ) ) or \
  13. ( sys.platform == 'darwin' and get_config_vars().get('UNIVERSALSDK', '').strip() ) ):
  14. plat = 'macosx-10.3-fat'
  15. if sys.platform == "sunos5" and not (plat.endswith('_32') or plat.endswith('_64')):
  16. if sys.maxint > 2**31:
  17. plat += '_64'
  18. else:
  19. plat += '_32'
  20. if sys.platform == "linux2" and sys.maxint < 2**31 and plat.endswith( '-x86_64' ):
  21. plat = plat.replace( '-x86_64', '-i686' )
  22. if not (plat.endswith('-ucs2') or plat.endswith('-ucs4')):
  23. if sys.maxunicode > 2**16:
  24. plat += '-ucs4'
  25. else:
  26. plat += '-ucs2'
  27. return plat
  28. try:
  29. assert pkg_resources._get_build_platform
  30. except:
  31. pkg_resources._get_build_platform = pkg_resources.get_build_platform
  32. pkg_resources.get_build_platform = _get_build_platform
  33. pkg_resources.get_platform = _get_build_platform
  34. # patch compatible_platforms() to allow for Solaris binary compatibility
  35. solarisVersionString = re.compile(r"solaris-(\d)\.(\d+)-(.*)")
  36. def _compatible_platforms(provided,required):
  37. # this is a bit kludgey since we need to know a bit about what happened in
  38. # the original method
  39. if provided is None or required is None or provided==required:
  40. return True # easy case
  41. reqMac = pkg_resources.macosVersionString.match(required)
  42. if reqMac:
  43. return pkg_resources._compatible_platforms(provided,required)
  44. reqSol = solarisVersionString.match(required)
  45. if reqSol:
  46. provSol = solarisVersionString.match(provided)
  47. if not provSol:
  48. return False
  49. if provSol.group(1) != reqSol.group(1) or \
  50. provSol.group(3) != reqSol.group(3):
  51. return False
  52. if int(provSol.group(2)) > int(reqSol.group(2)):
  53. return False
  54. return True
  55. return False
  56. try:
  57. assert pkg_resources._compatible_platforms
  58. except:
  59. pkg_resources._compatible_platforms = pkg_resources.compatible_platforms
  60. pkg_resources.compatible_platforms = _compatible_platforms
  61. # patch to insert eggs at the beginning of sys.path instead of at the end
  62. def _insert_on(self, path, loc = None):
  63. """Insert self.location in path before its nearest parent directory"""
  64. loc = loc or self.location
  65. if not loc:
  66. return
  67. nloc = pkg_resources._normalize_cached(loc)
  68. npath= [(p and pkg_resources._normalize_cached(p) or p) for p in path]
  69. #if path is sys.path:
  70. # self.check_version_conflict()
  71. path.insert(0, loc)
  72. # remove dups
  73. while 1:
  74. try:
  75. np = npath.index(nloc, 1)
  76. except ValueError:
  77. break
  78. else:
  79. del npath[np], path[np]
  80. return
  81. try:
  82. assert pkg_resources.Distribution._insert_on
  83. except:
  84. pkg_resources.Distribution._insert_on = pkg_resources.Distribution.insert_on
  85. pkg_resources.Distribution.insert_on = _insert_on
  86. # compat: BadZipFile introduced in Python 2.7
  87. import zipfile
  88. if not hasattr( zipfile, 'BadZipFile' ):
  89. zipfile.BadZipFile = zipfile.error
  90. # compat: patch to add the NullHandler class to logging
  91. import logging
  92. if not hasattr( logging, 'NullHandler' ):
  93. class NullHandler( logging.Handler ):
  94. def emit( self, record ):
  95. pass
  96. logging.NullHandler = NullHandler
  97. import galaxy.eggs