PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/__init__.py

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