<s> from __future__ import absolute_import , division , print_function <EOL> import sys <EOL> from distutils . ccompiler import new_compiler <EOL> from distutils . dist import Distribution <EOL> from cffi import FFI <EOL> def build_ffi_for_binding ( module_name , module_prefix , modules , pre_include = "<STR_LIT>" , <EOL> post_include = "<STR_LIT>" , libraries = [ ] , extra_compile_args = [ ] , <EOL> extra_link_args = [ ] ) : <EOL> """<STR_LIT>""" <EOL> types = [ ] <EOL> includes = [ ] <EOL> functions = [ ] <EOL> macros = [ ] <EOL> customizations = [ ] <EOL> for name in modules : <EOL> __import__ ( module_prefix + name ) <EOL> module = sys . modules [ module_prefix + name ] <EOL> types . append ( module . TYPES ) <EOL> macros . append ( module . MACROS ) <EOL> functions . append ( module . FUNCTIONS ) <EOL> includes . append ( module . INCLUDES ) <EOL> customizations . append ( module . CUSTOMIZATIONS ) <EOL> verify_source = "<STR_LIT:\n>" . join ( <EOL> [ pre_include ] + <EOL> includes + <EOL> [ post_include ] + <EOL> functions + <EOL> customizations <EOL> ) <EOL> ffi = build_ffi ( <EOL> module_name , <EOL> cdef_source = "<STR_LIT:\n>" . join ( types + functions + macros ) , <EOL> verify_source = verify_source , <EOL> libraries = libraries , <EOL> extra_compile_args = extra_compile_args , <EOL> extra_link_args = extra_link_args , <EOL> ) <EOL> return ffi <EOL> def build_ffi ( module_name , cdef_source , verify_source , libraries = [ ] , <EOL> extra_compile_args = [ ] , extra_link_args = [ ] ) : <EOL> ffi = FFI ( ) <EOL> ffi . cdef ( cdef_source ) <EOL> ffi . set_source ( <EOL> module_name , <EOL> verify_source , <EOL> libraries = libraries , <EOL> extra_compile_args = extra_compile_args , <EOL> extra_link_args = extra_link_args , <EOL> ) <EOL> return ffi <EOL> def extra_link_args ( compiler_type ) : <EOL> if compiler_type == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> return [ ] <EOL> def compiler_type ( ) : <EOL> """<STR_LIT>""" <EOL> dist = Distribution ( ) <EOL> dist . parse_config_files ( ) <EOL> cmd = dist . get_command_obj ( '<STR_LIT>' ) <EOL> cmd . ensure_finalized ( ) <EOL> compiler = new_compiler ( compiler = cmd . compiler ) <EOL> return compiler . compiler_type </s>
