<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import sys <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> _UNIVERSAL_CONFIG_VARS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> _COMPILER_CONFIG_VARS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> _INITPRE = '<STR_LIT>' <EOL> def _find_executable ( executable , path = None ) : <EOL> """<STR_LIT>""" <EOL> if path is None : <EOL> path = os . environ [ '<STR_LIT>' ] <EOL> paths = path . split ( os . pathsep ) <EOL> base , ext = os . path . splitext ( executable ) <EOL> if ( sys . platform == '<STR_LIT:win32>' or os . name == '<STR_LIT>' ) and ( ext != '<STR_LIT>' ) : <EOL> executable = executable + '<STR_LIT>' <EOL> if not os . path . isfile ( executable ) : <EOL> for p in paths : <EOL> f = os . path . join ( p , executable ) <EOL> if os . path . isfile ( f ) : <EOL> return f <EOL> return None <EOL> else : <EOL> return executable <EOL> def _read_output ( commandstring ) : <EOL> """<STR_LIT>""" <EOL> import contextlib <EOL> try : <EOL> import tempfile <EOL> fp = tempfile . NamedTemporaryFile ( ) <EOL> except ImportError : <EOL> fp = open ( "<STR_LIT>" % ( <EOL> os . getpid ( ) , ) , "<STR_LIT>" ) <EOL> with contextlib . closing ( fp ) as fp : <EOL> cmd = "<STR_LIT>" % ( commandstring , fp . name ) <EOL> return fp . read ( ) . strip ( ) if not os . system ( cmd ) else None <EOL> def _find_build_tool ( toolname ) : <EOL> """<STR_LIT>""" <EOL> return ( _find_executable ( toolname ) <EOL> or _read_output ( "<STR_LIT>" % ( toolname , ) ) <EOL> or '<STR_LIT>' <EOL> ) <EOL> _SYSTEM_VERSION = None <EOL> def _get_system_version ( ) : <EOL> """<STR_LIT>""" <EOL> global _SYSTEM_VERSION <EOL> if _SYSTEM_VERSION is None : <EOL> _SYSTEM_VERSION = '<STR_LIT>' <EOL> try : <EOL> f = open ( '<STR_LIT>' ) <EOL> except IOError : <EOL> pass <EOL> else : <EOL> try : <EOL> m = re . search ( r'<STR_LIT>' <EOL> r'<STR_LIT>' , f . read ( ) ) <EOL> finally : <EOL> f . close ( ) <EOL> if m is not None : <EOL> _SYSTEM_VERSION = '<STR_LIT:.>' . join ( m . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:.>' ) [ : <NUM_LIT:2> ] ) <EOL> return _SYSTEM_VERSION <EOL> def _remove_original_values ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> for k in list ( _config_vars ) : <EOL> if k . startswith ( _INITPRE ) : <EOL> del _config_vars [ k ] <EOL> def _save_modified_value ( _config_vars , cv , newvalue ) : <EOL> """<STR_LIT>""" <EOL> oldvalue = _config_vars . get ( cv , '<STR_LIT>' ) <EOL> if ( oldvalue != newvalue ) and ( _INITPRE + cv not in _config_vars ) : <EOL> _config_vars [ _INITPRE + cv ] = oldvalue <EOL> _config_vars [ cv ] = newvalue <EOL> def _supports_universal_builds ( ) : <EOL> """<STR_LIT>""" <EOL> osx_version = _get_system_version ( ) <EOL> if osx_version : <EOL> try : <EOL> osx_version = tuple ( int ( i ) for i in osx_version . split ( '<STR_LIT:.>' ) ) <EOL> except ValueError : <EOL> osx_version = '<STR_LIT>' <EOL> return bool ( osx_version >= ( <NUM_LIT:10> , <NUM_LIT:4> ) ) if osx_version else False <EOL> def _find_appropriate_compiler ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in os . environ : <EOL> return _config_vars <EOL> cc = oldcc = _config_vars [ '<STR_LIT>' ] . split ( ) [ <NUM_LIT:0> ] <EOL> if not _find_executable ( cc ) : <EOL> cc = _find_build_tool ( '<STR_LIT>' ) <EOL> elif os . path . basename ( cc ) . startswith ( '<STR_LIT>' ) : <EOL> data = _read_output ( "<STR_LIT>" <EOL> % ( cc . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) , ) ) <EOL> if data and '<STR_LIT>' in data : <EOL> cc = _find_build_tool ( '<STR_LIT>' ) <EOL> if not cc : <EOL> raise SystemError ( <EOL> "<STR_LIT>" ) <EOL> if cc != oldcc : <EOL> for cv in _COMPILER_CONFIG_VARS : <EOL> if cv in _config_vars and cv not in os . environ : <EOL> cv_split = _config_vars [ cv ] . split ( ) <EOL> cv_split [ <NUM_LIT:0> ] = cc if cv != '<STR_LIT>' else cc + '<STR_LIT>' <EOL> _save_modified_value ( _config_vars , cv , '<STR_LIT:U+0020>' . join ( cv_split ) ) <EOL> return _config_vars <EOL> def _remove_universal_flags ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> for cv in _UNIVERSAL_CONFIG_VARS : <EOL> if cv in _config_vars and cv not in os . environ : <EOL> flags = _config_vars [ cv ] <EOL> flags = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , flags ) <EOL> flags = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , flags ) <EOL> _save_modified_value ( _config_vars , cv , flags ) <EOL> return _config_vars <EOL> def _remove_unsupported_archs ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in os . environ : <EOL> return _config_vars <EOL> if re . search ( '<STR_LIT>' , _config_vars [ '<STR_LIT>' ] ) is not None : <EOL> status = os . system ( <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> % ( _config_vars [ '<STR_LIT>' ] . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) , ) ) <EOL> if status : <EOL> for cv in _UNIVERSAL_CONFIG_VARS : <EOL> if cv in _config_vars and cv not in os . environ : <EOL> flags = _config_vars [ cv ] <EOL> flags = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , flags ) <EOL> _save_modified_value ( _config_vars , cv , flags ) <EOL> return _config_vars <EOL> def _override_all_archs ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in os . environ : <EOL> arch = os . environ [ '<STR_LIT>' ] <EOL> for cv in _UNIVERSAL_CONFIG_VARS : <EOL> if cv in _config_vars and '<STR_LIT>' in _config_vars [ cv ] : <EOL> flags = _config_vars [ cv ] <EOL> flags = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , flags ) <EOL> flags = flags + '<STR_LIT:U+0020>' + arch <EOL> _save_modified_value ( _config_vars , cv , flags ) <EOL> return _config_vars <EOL> def _check_for_unavailable_sdk ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> cflags = _config_vars . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> m = re . search ( r'<STR_LIT>' , cflags ) <EOL> if m is not None : <EOL> sdk = m . group ( <NUM_LIT:1> ) <EOL> if not os . path . exists ( sdk ) : <EOL> for cv in _UNIVERSAL_CONFIG_VARS : <EOL> if cv in _config_vars and cv not in os . environ : <EOL> flags = _config_vars [ cv ] <EOL> flags = re . sub ( r'<STR_LIT>' , '<STR_LIT:U+0020>' , flags ) <EOL> _save_modified_value ( _config_vars , cv , flags ) <EOL> return _config_vars <EOL> def compiler_fixup ( compiler_so , cc_args ) : <EOL> """<STR_LIT>""" <EOL> stripArch = stripSysroot = False <EOL> compiler_so = list ( compiler_so ) <EOL> if not _supports_universal_builds ( ) : <EOL> stripArch = stripSysroot = True <EOL> else : <EOL> stripArch = '<STR_LIT>' in cc_args <EOL> stripSysroot = '<STR_LIT>' in cc_args <EOL> if stripArch or '<STR_LIT>' in os . environ : <EOL> while True : <EOL> try : <EOL> index = compiler_so . index ( '<STR_LIT>' ) <EOL> del compiler_so [ index : index + <NUM_LIT:2> ] <EOL> except ValueError : <EOL> break <EOL> if '<STR_LIT>' in os . environ and not stripArch : <EOL> compiler_so = compiler_so + os . environ [ '<STR_LIT>' ] . split ( ) <EOL> if stripSysroot : <EOL> while True : <EOL> try : <EOL> index = compiler_so . index ( '<STR_LIT>' ) <EOL> del compiler_so [ index : index + <NUM_LIT:2> ] <EOL> except ValueError : <EOL> break <EOL> sysroot = None <EOL> if '<STR_LIT>' in cc_args : <EOL> idx = cc_args . index ( '<STR_LIT>' ) <EOL> sysroot = cc_args [ idx + <NUM_LIT:1> ] <EOL> elif '<STR_LIT>' in compiler_so : <EOL> idx = compiler_so . index ( '<STR_LIT>' ) <EOL> sysroot = compiler_so [ idx + <NUM_LIT:1> ] <EOL> if sysroot and not os . path . isdir ( sysroot ) : <EOL> from distutils import log <EOL> log . warn ( "<STR_LIT>" , <EOL> sysroot ) <EOL> log . warn ( "<STR_LIT>" ) <EOL> return compiler_so <EOL> def customize_config_vars ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> if not _supports_universal_builds ( ) : <EOL> _remove_universal_flags ( _config_vars ) <EOL> _override_all_archs ( _config_vars ) <EOL> _check_for_unavailable_sdk ( _config_vars ) <EOL> return _config_vars <EOL> def customize_compiler ( _config_vars ) : <EOL> """<STR_LIT>""" <EOL> _find_appropriate_compiler ( _config_vars ) <EOL> _remove_unsupported_archs ( _config_vars ) <EOL> _override_all_archs ( _config_vars ) <EOL> return _config_vars <EOL> def get_platform_osx ( _config_vars , osname , release , machine ) : <EOL> """<STR_LIT>""" <EOL> macver = _config_vars . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> macrelease = _get_system_version ( ) or macver <EOL> macver = macver or macrelease <EOL> if macver : <EOL> release = macver <EOL> osname = "<STR_LIT>" <EOL> cflags = _config_vars . get ( _INITPRE + '<STR_LIT>' , <EOL> _config_vars . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if ( ( macrelease + '<STR_LIT:.>' ) >= '<STR_LIT>' and <EOL> '<STR_LIT>' in cflags . strip ( ) ) : <EOL> machine = '<STR_LIT>' <EOL> archs = re . findall ( '<STR_LIT>' , cflags ) <EOL> archs = tuple ( sorted ( set ( archs ) ) ) <EOL> if len ( archs ) == <NUM_LIT:1> : <EOL> machine = archs [ <NUM_LIT:0> ] <EOL> elif archs == ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> elif archs == ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> elif archs == ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> elif archs == ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> elif archs == ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( archs , ) ) <EOL> elif machine == '<STR_LIT>' : <EOL> if sys . maxint >= <NUM_LIT:2> ** <NUM_LIT:32> : <EOL> machine = '<STR_LIT>' <EOL> elif machine in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if sys . maxint >= <NUM_LIT:2> ** <NUM_LIT:32> : <EOL> machine = '<STR_LIT>' <EOL> else : <EOL> machine = '<STR_LIT>' <EOL> return ( osname , release , machine ) </s>
