<s> import sys , os , os . path <EOL> from distutils . core import Extension <EOL> from distutils . errors import DistutilsOptionError <EOL> from versioninfo import get_base_dir , split_version <EOL> try : <EOL> from Cython . Distutils import build_ext as build_pyx <EOL> import Cython . Compiler . Version <EOL> CYTHON_INSTALLED = True <EOL> except ImportError : <EOL> CYTHON_INSTALLED = False <EOL> EXT_MODULES = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> PACKAGE_PATH = "<STR_LIT>" % ( os . path . sep , os . path . sep ) <EOL> INCLUDE_PACKAGE_PATH = PACKAGE_PATH + '<STR_LIT>' <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> _system_encoding = sys . getdefaultencoding ( ) <EOL> if _system_encoding is None : <EOL> _system_encoding = "<STR_LIT>" <EOL> def decode_input ( data ) : <EOL> if isinstance ( data , str ) : <EOL> return data <EOL> return data . decode ( _system_encoding ) <EOL> else : <EOL> def decode_input ( data ) : <EOL> return data <EOL> def env_var ( name ) : <EOL> value = os . getenv ( name ) <EOL> if value : <EOL> value = decode_input ( value ) <EOL> if sys . platform == '<STR_LIT:win32>' and '<STR_LIT:;>' in value : <EOL> return value . split ( '<STR_LIT:;>' ) <EOL> else : <EOL> return value . split ( ) <EOL> else : <EOL> return [ ] <EOL> def ext_modules ( static_include_dirs , static_library_dirs , <EOL> static_cflags , static_binaries ) : <EOL> global XML2_CONFIG , XSLT_CONFIG <EOL> if OPTION_BUILD_LIBXML2XSLT : <EOL> from buildlibxml import build_libxml2xslt , get_prebuilt_libxml2xslt <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> get_prebuilt_libxml2xslt ( <EOL> OPTION_DOWNLOAD_DIR , static_include_dirs , static_library_dirs ) <EOL> else : <EOL> XML2_CONFIG , XSLT_CONFIG = build_libxml2xslt ( <EOL> OPTION_DOWNLOAD_DIR , '<STR_LIT>' , <EOL> static_include_dirs , static_library_dirs , <EOL> static_cflags , static_binaries , <EOL> libiconv_version = OPTION_LIBICONV_VERSION , <EOL> libxml2_version = OPTION_LIBXML2_VERSION , <EOL> libxslt_version = OPTION_LIBXSLT_VERSION , <EOL> multicore = OPTION_MULTICORE ) <EOL> if OPTION_WITHOUT_OBJECTIFY : <EOL> modules = [ entry for entry in EXT_MODULES <EOL> if '<STR_LIT>' not in entry ] <EOL> else : <EOL> modules = EXT_MODULES <EOL> c_files_exist = [ os . path . exists ( '<STR_LIT>' % ( PACKAGE_PATH , module ) ) for module in modules ] <EOL> if CYTHON_INSTALLED and ( OPTION_WITH_CYTHON or False in c_files_exist ) : <EOL> source_extension = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % Cython . Compiler . Version . version ) <EOL> from Cython . Compiler import Options <EOL> Options . generate_cleanup_code = <NUM_LIT:3> <EOL> Options . clear_to_none = False <EOL> elif not OPTION_WITHOUT_CYTHON and False in c_files_exist : <EOL> for exists , module in zip ( c_files_exist , modules ) : <EOL> if not exists : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> PACKAGE_PATH , module ) ) <EOL> else : <EOL> if False in c_files_exist : <EOL> for exists , module in zip ( c_files_exist , modules ) : <EOL> if not exists : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( PACKAGE_PATH , module ) ) <EOL> source_extension = "<STR_LIT>" <EOL> print ( "<STR_LIT>" ) <EOL> lib_versions = get_library_versions ( ) <EOL> if lib_versions [ <NUM_LIT:0> ] : <EOL> print ( "<STR_LIT>" % <EOL> lib_versions ) <EOL> else : <EOL> print ( "<STR_LIT>" % <EOL> lib_versions [ <NUM_LIT:1> ] ) <EOL> _include_dirs = include_dirs ( static_include_dirs ) <EOL> _library_dirs = library_dirs ( static_library_dirs ) <EOL> _cflags = cflags ( static_cflags ) <EOL> _define_macros = define_macros ( ) <EOL> _libraries = libraries ( ) <EOL> _include_dirs . append ( os . path . join ( get_base_dir ( ) , INCLUDE_PACKAGE_PATH ) ) <EOL> if _library_dirs : <EOL> message = "<STR_LIT>" <EOL> if len ( _library_dirs ) > <NUM_LIT:1> : <EOL> print ( message + "<STR_LIT>" ) <EOL> for dir in _library_dirs : <EOL> print ( "<STR_LIT:U+0020>" + dir ) <EOL> else : <EOL> print ( message + "<STR_LIT>" + <EOL> _library_dirs [ <NUM_LIT:0> ] ) <EOL> if OPTION_AUTO_RPATH : <EOL> runtime_library_dirs = _library_dirs <EOL> else : <EOL> runtime_library_dirs = [ ] <EOL> if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS : <EOL> from Cython . Compiler import Errors <EOL> Errors . LEVEL = <NUM_LIT:0> <EOL> result = [ ] <EOL> for module in modules : <EOL> main_module_source = PACKAGE_PATH + module + source_extension <EOL> result . append ( <EOL> Extension ( <EOL> module , <EOL> sources = [ main_module_source ] , <EOL> depends = find_dependencies ( module ) , <EOL> extra_compile_args = _cflags , <EOL> extra_objects = static_binaries , <EOL> define_macros = _define_macros , <EOL> include_dirs = _include_dirs , <EOL> library_dirs = _library_dirs , <EOL> runtime_library_dirs = runtime_library_dirs , <EOL> libraries = _libraries , <EOL> ) ) <EOL> if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB : <EOL> for ext in result : <EOL> ext . cython_gdb = True <EOL> if CYTHON_INSTALLED and source_extension == '<STR_LIT>' : <EOL> from Cython . Build import cythonize <EOL> result = cythonize ( result ) <EOL> return result <EOL> def find_dependencies ( module ) : <EOL> if not CYTHON_INSTALLED : <EOL> return [ ] <EOL> base_dir = get_base_dir ( ) <EOL> package_dir = os . path . join ( base_dir , PACKAGE_PATH ) <EOL> includes_dir = os . path . join ( base_dir , INCLUDE_PACKAGE_PATH ) <EOL> pxd_files = [ os . path . join ( includes_dir , filename ) <EOL> for filename in os . listdir ( includes_dir ) <EOL> if filename . endswith ( '<STR_LIT>' ) ] <EOL> if '<STR_LIT>' in module : <EOL> pxi_files = [ os . path . join ( PACKAGE_PATH , filename ) <EOL> for filename in os . listdir ( package_dir ) <EOL> if filename . endswith ( '<STR_LIT>' ) <EOL> and '<STR_LIT>' not in filename ] <EOL> pxd_files = [ filename for filename in pxd_files <EOL> if '<STR_LIT>' not in filename ] <EOL> elif '<STR_LIT>' in module : <EOL> pxi_files = [ os . path . join ( PACKAGE_PATH , '<STR_LIT>' ) ] <EOL> else : <EOL> pxi_files = [ ] <EOL> return pxd_files + pxi_files <EOL> def extra_setup_args ( ) : <EOL> result = { } <EOL> if CYTHON_INSTALLED : <EOL> result [ '<STR_LIT>' ] = { '<STR_LIT>' : build_pyx } <EOL> return result <EOL> def libraries ( ) : <EOL> if sys . platform in ( '<STR_LIT:win32>' , ) : <EOL> libs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if OPTION_STATIC : <EOL> libs = [ '<STR_LIT>' % lib for lib in libs ] <EOL> libs . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> elif OPTION_STATIC : <EOL> libs = [ '<STR_LIT:z>' , '<STR_LIT:m>' ] <EOL> else : <EOL> libs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:z>' , '<STR_LIT:m>' ] <EOL> return libs <EOL> def library_dirs ( static_library_dirs ) : <EOL> if OPTION_STATIC : <EOL> if not static_library_dirs : <EOL> static_library_dirs = env_var ( '<STR_LIT>' ) <EOL> assert static_library_dirs , "<STR_LIT>" <EOL> return static_library_dirs <EOL> result = [ ] <EOL> possible_library_dirs = flags ( '<STR_LIT>' ) <EOL> for possible_library_dir in possible_library_dirs : <EOL> if possible_library_dir . startswith ( '<STR_LIT>' ) : <EOL> result . append ( possible_library_dir [ <NUM_LIT:2> : ] ) <EOL> return result <EOL> def include_dirs ( static_include_dirs ) : <EOL> if OPTION_STATIC : <EOL> if not static_include_dirs : <EOL> static_include_dirs = env_var ( '<STR_LIT>' ) <EOL> return static_include_dirs <EOL> result = [ ] <EOL> possible_include_dirs = flags ( '<STR_LIT>' ) <EOL> for possible_include_dir in possible_include_dirs : <EOL> if possible_include_dir . startswith ( '<STR_LIT>' ) : <EOL> result . append ( possible_include_dir [ <NUM_LIT:2> : ] ) <EOL> return result <EOL> def cflags ( static_cflags ) : <EOL> result = [ ] <EOL> if not OPTION_SHOW_WARNINGS : <EOL> result . append ( '<STR_LIT>' ) <EOL> if OPTION_DEBUG_GCC : <EOL> result . append ( '<STR_LIT>' ) <EOL> if OPTION_STATIC : <EOL> if not static_cflags : <EOL> static_cflags = env_var ( '<STR_LIT>' ) <EOL> result . extend ( static_cflags ) <EOL> else : <EOL> possible_cflags = flags ( '<STR_LIT>' ) <EOL> for possible_cflag in possible_cflags : <EOL> if not possible_cflag . startswith ( '<STR_LIT>' ) : <EOL> result . append ( possible_cflag ) <EOL> if sys . platform in ( '<STR_LIT>' , ) : <EOL> for opt in result : <EOL> if '<STR_LIT>' in opt : <EOL> break <EOL> else : <EOL> result . append ( '<STR_LIT>' ) <EOL> return result <EOL> def define_macros ( ) : <EOL> macros = [ ] <EOL> if OPTION_WITHOUT_ASSERT : <EOL> macros . append ( ( '<STR_LIT>' , None ) ) <EOL> if OPTION_WITHOUT_THREADING : <EOL> macros . append ( ( '<STR_LIT>' , None ) ) <EOL> if OPTION_WITH_REFNANNY : <EOL> macros . append ( ( '<STR_LIT>' , None ) ) <EOL> if OPTION_WITH_UNICODE_STRINGS : <EOL> macros . append ( ( '<STR_LIT>' , '<STR_LIT:1>' ) ) <EOL> return macros <EOL> _ERROR_PRINTED = False <EOL> def run_command ( cmd , * args ) : <EOL> if not cmd : <EOL> return '<STR_LIT>' <EOL> if args : <EOL> cmd = '<STR_LIT:U+0020>' . join ( ( cmd , ) + args ) <EOL> try : <EOL> import subprocess <EOL> except ImportError : <EOL> sf , rf , ef = os . popen3 ( cmd ) <EOL> sf . close ( ) <EOL> errors = ef . read ( ) <EOL> stdout_data = rf . read ( ) <EOL> else : <EOL> p = subprocess . Popen ( cmd , shell = True , <EOL> stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> stdout_data , errors = p . communicate ( ) <EOL> global _ERROR_PRINTED <EOL> if errors and not _ERROR_PRINTED : <EOL> _ERROR_PRINTED = True <EOL> print ( "<STR_LIT>" % errors ) <EOL> print ( "<STR_LIT>" ) <EOL> return decode_input ( stdout_data ) . strip ( ) <EOL> def get_library_versions ( ) : <EOL> xml2_version = run_command ( find_xml2_config ( ) , "<STR_LIT>" ) <EOL> xslt_version = run_command ( find_xslt_config ( ) , "<STR_LIT>" ) <EOL> return xml2_version , xslt_version <EOL> def flags ( option ) : <EOL> xml2_flags = run_command ( find_xml2_config ( ) , "<STR_LIT>" % option ) <EOL> xslt_flags = run_command ( find_xslt_config ( ) , "<STR_LIT>" % option ) <EOL> flag_list = xml2_flags . split ( ) <EOL> for flag in xslt_flags . split ( ) : <EOL> if flag not in flag_list : <EOL> flag_list . append ( flag ) <EOL> return flag_list <EOL> XSLT_CONFIG = None <EOL> XML2_CONFIG = None <EOL> def find_xml2_config ( ) : <EOL> global XML2_CONFIG <EOL> if XML2_CONFIG : <EOL> return XML2_CONFIG <EOL> option = '<STR_LIT>' <EOL> for arg in sys . argv : <EOL> if arg . startswith ( option ) : <EOL> sys . argv . remove ( arg ) <EOL> XML2_CONFIG = arg [ len ( option ) : ] <EOL> return XML2_CONFIG <EOL> else : <EOL> XML2_CONFIG = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return XML2_CONFIG <EOL> def find_xslt_config ( ) : <EOL> global XSLT_CONFIG <EOL> if XSLT_CONFIG : <EOL> return XSLT_CONFIG <EOL> option = '<STR_LIT>' <EOL> for arg in sys . argv : <EOL> if arg . startswith ( option ) : <EOL> sys . argv . remove ( arg ) <EOL> XSLT_CONFIG = arg [ len ( option ) : ] <EOL> return XSLT_CONFIG <EOL> else : <EOL> XSLT_CONFIG = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return XSLT_CONFIG <EOL> def has_option ( name ) : <EOL> try : <EOL> sys . argv . remove ( '<STR_LIT>' % name ) <EOL> return True <EOL> except ValueError : <EOL> pass <EOL> env_val = os . getenv ( name . upper ( ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) , '<STR_LIT:false>' ) . lower ( ) <EOL> if env_val == "<STR_LIT:true>" : <EOL> return True <EOL> return False <EOL> def option_value ( name ) : <EOL> for index , option in enumerate ( sys . argv ) : <EOL> if option == '<STR_LIT>' + name : <EOL> if index + <NUM_LIT:1> >= len ( sys . argv ) : <EOL> raise DistutilsOptionError ( <EOL> '<STR_LIT>' % option ) <EOL> value = sys . argv [ index + <NUM_LIT:1> ] <EOL> sys . argv [ index : index + <NUM_LIT:2> ] = [ ] <EOL> return value <EOL> if option . startswith ( '<STR_LIT>' + name + '<STR_LIT:=>' ) : <EOL> value = option [ len ( name ) + <NUM_LIT:3> : ] <EOL> sys . argv [ index : index + <NUM_LIT:1> ] = [ ] <EOL> return value <EOL> env_val = os . getenv ( name . upper ( ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) ) <EOL> return env_val <EOL> staticbuild = bool ( os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> OPTION_WITHOUT_OBJECTIFY = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITH_UNICODE_STRINGS = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITHOUT_ASSERT = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITHOUT_THREADING = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITHOUT_CYTHON = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITH_CYTHON = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITH_CYTHON_GDB = has_option ( '<STR_LIT>' ) <EOL> OPTION_WITH_REFNANNY = has_option ( '<STR_LIT>' ) <EOL> if OPTION_WITHOUT_CYTHON : <EOL> CYTHON_INSTALLED = False <EOL> OPTION_STATIC = staticbuild or has_option ( '<STR_LIT>' ) <EOL> OPTION_DEBUG_GCC = has_option ( '<STR_LIT>' ) <EOL> OPTION_SHOW_WARNINGS = has_option ( '<STR_LIT>' ) <EOL> OPTION_AUTO_RPATH = has_option ( '<STR_LIT>' ) <EOL> OPTION_BUILD_LIBXML2XSLT = staticbuild or has_option ( '<STR_LIT>' ) <EOL> if OPTION_BUILD_LIBXML2XSLT : <EOL> OPTION_STATIC = True <EOL> OPTION_LIBXML2_VERSION = option_value ( '<STR_LIT>' ) <EOL> OPTION_LIBXSLT_VERSION = option_value ( '<STR_LIT>' ) <EOL> OPTION_LIBICONV_VERSION = option_value ( '<STR_LIT>' ) <EOL> OPTION_MULTICORE = option_value ( '<STR_LIT>' ) <EOL> OPTION_DOWNLOAD_DIR = option_value ( '<STR_LIT>' ) <EOL> if OPTION_DOWNLOAD_DIR is None : <EOL> OPTION_DOWNLOAD_DIR = '<STR_LIT>' </s>
