<s> from distutils . command . build_ext import build_ext as _du_build_ext <EOL> from distutils . file_util import copy_file <EOL> from distutils . ccompiler import new_compiler <EOL> from distutils . sysconfig import customize_compiler <EOL> from distutils . errors import DistutilsError <EOL> from distutils import log <EOL> import os <EOL> import sys <EOL> import itertools <EOL> from setuptools . extension import Library <EOL> try : <EOL> from Pyrex . Distutils . build_ext import build_ext as _build_ext <EOL> except ImportError : <EOL> _build_ext = _du_build_ext <EOL> try : <EOL> from sysconfig import _CONFIG_VARS <EOL> except ImportError : <EOL> from distutils . sysconfig import get_config_var <EOL> get_config_var ( "<STR_LIT>" ) <EOL> del get_config_var <EOL> from distutils . sysconfig import _config_vars as _CONFIG_VARS <EOL> have_rtld = False <EOL> use_stubs = False <EOL> libtype = '<STR_LIT>' <EOL> if sys . platform == "<STR_LIT>" : <EOL> use_stubs = True <EOL> elif os . name != '<STR_LIT>' : <EOL> try : <EOL> import dl <EOL> use_stubs = have_rtld = hasattr ( dl , '<STR_LIT>' ) <EOL> except ImportError : <EOL> pass <EOL> if_dl = lambda s : s if have_rtld else '<STR_LIT>' <EOL> class build_ext ( _build_ext ) : <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> old_inplace , self . inplace = self . inplace , <NUM_LIT:0> <EOL> _build_ext . run ( self ) <EOL> self . inplace = old_inplace <EOL> if old_inplace : <EOL> self . copy_extensions_to_source ( ) <EOL> def copy_extensions_to_source ( self ) : <EOL> build_py = self . get_finalized_command ( '<STR_LIT>' ) <EOL> for ext in self . extensions : <EOL> fullname = self . get_ext_fullname ( ext . name ) <EOL> filename = self . get_ext_filename ( fullname ) <EOL> modpath = fullname . split ( '<STR_LIT:.>' ) <EOL> package = '<STR_LIT:.>' . join ( modpath [ : - <NUM_LIT:1> ] ) <EOL> package_dir = build_py . get_package_dir ( package ) <EOL> dest_filename = os . path . join ( package_dir , <EOL> os . path . basename ( filename ) ) <EOL> src_filename = os . path . join ( self . build_lib , filename ) <EOL> copy_file ( <EOL> src_filename , dest_filename , verbose = self . verbose , <EOL> dry_run = self . dry_run <EOL> ) <EOL> if ext . _needs_stub : <EOL> self . write_stub ( package_dir or os . curdir , ext , True ) <EOL> if _build_ext is not _du_build_ext and not hasattr ( _build_ext , <EOL> '<STR_LIT>' ) : <EOL> def swig_sources ( self , sources , * otherargs ) : <EOL> sources = _build_ext . swig_sources ( self , sources ) or sources <EOL> return _du_build_ext . swig_sources ( self , sources , * otherargs ) <EOL> def get_ext_filename ( self , fullname ) : <EOL> filename = _build_ext . get_ext_filename ( self , fullname ) <EOL> if fullname in self . ext_map : <EOL> ext = self . ext_map [ fullname ] <EOL> if isinstance ( ext , Library ) : <EOL> fn , ext = os . path . splitext ( filename ) <EOL> return self . shlib_compiler . library_filename ( fn , libtype ) <EOL> elif use_stubs and ext . _links_to_dynamic : <EOL> d , fn = os . path . split ( filename ) <EOL> return os . path . join ( d , '<STR_LIT>' + fn ) <EOL> return filename <EOL> def initialize_options ( self ) : <EOL> _build_ext . initialize_options ( self ) <EOL> self . shlib_compiler = None <EOL> self . shlibs = [ ] <EOL> self . ext_map = { } <EOL> def finalize_options ( self ) : <EOL> _build_ext . finalize_options ( self ) <EOL> self . extensions = self . extensions or [ ] <EOL> self . check_extensions_list ( self . extensions ) <EOL> self . shlibs = [ ext for ext in self . extensions <EOL> if isinstance ( ext , Library ) ] <EOL> if self . shlibs : <EOL> self . setup_shlib_compiler ( ) <EOL> for ext in self . extensions : <EOL> ext . _full_name = self . get_ext_fullname ( ext . name ) <EOL> for ext in self . extensions : <EOL> fullname = ext . _full_name <EOL> self . ext_map [ fullname ] = ext <EOL> self . ext_map [ fullname . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] ] = ext <EOL> ltd = self . shlibs and self . links_to_dynamic ( ext ) or False <EOL> ns = ltd and use_stubs and not isinstance ( ext , Library ) <EOL> ext . _links_to_dynamic = ltd <EOL> ext . _needs_stub = ns <EOL> filename = ext . _file_name = self . get_ext_filename ( fullname ) <EOL> libdir = os . path . dirname ( os . path . join ( self . build_lib , filename ) ) <EOL> if ltd and libdir not in ext . library_dirs : <EOL> ext . library_dirs . append ( libdir ) <EOL> if ltd and use_stubs and os . curdir not in ext . runtime_library_dirs : <EOL> ext . runtime_library_dirs . append ( os . curdir ) <EOL> def setup_shlib_compiler ( self ) : <EOL> compiler = self . shlib_compiler = new_compiler ( <EOL> compiler = self . compiler , dry_run = self . dry_run , force = self . force <EOL> ) <EOL> if sys . platform == "<STR_LIT>" : <EOL> tmp = _CONFIG_VARS . copy ( ) <EOL> try : <EOL> _CONFIG_VARS [ '<STR_LIT>' ] = ( <EOL> "<STR_LIT>" ) <EOL> _CONFIG_VARS [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> _CONFIG_VARS [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> customize_compiler ( compiler ) <EOL> finally : <EOL> _CONFIG_VARS . clear ( ) <EOL> _CONFIG_VARS . update ( tmp ) <EOL> else : <EOL> customize_compiler ( compiler ) <EOL> if self . include_dirs is not None : <EOL> compiler . set_include_dirs ( self . include_dirs ) <EOL> if self . define is not None : <EOL> for ( name , value ) in self . define : <EOL> compiler . define_macro ( name , value ) <EOL> if self . undef is not None : <EOL> for macro in self . undef : <EOL> compiler . undefine_macro ( macro ) <EOL> if self . libraries is not None : <EOL> compiler . set_libraries ( self . libraries ) <EOL> if self . library_dirs is not None : <EOL> compiler . set_library_dirs ( self . library_dirs ) <EOL> if self . rpath is not None : <EOL> compiler . set_runtime_library_dirs ( self . rpath ) <EOL> if self . link_objects is not None : <EOL> compiler . set_link_objects ( self . link_objects ) <EOL> compiler . link_shared_object = link_shared_object . __get__ ( compiler ) <EOL> def get_export_symbols ( self , ext ) : <EOL> if isinstance ( ext , Library ) : <EOL> return ext . export_symbols <EOL> return _build_ext . get_export_symbols ( self , ext ) <EOL> def build_extension ( self , ext ) : <EOL> _compiler = self . compiler <EOL> try : <EOL> if isinstance ( ext , Library ) : <EOL> self . compiler = self . shlib_compiler <EOL> _build_ext . build_extension ( self , ext ) <EOL> if ext . _needs_stub : <EOL> cmd = self . get_finalized_command ( '<STR_LIT>' ) . build_lib <EOL> self . write_stub ( cmd , ext ) <EOL> finally : <EOL> self . compiler = _compiler <EOL> def links_to_dynamic ( self , ext ) : <EOL> """<STR_LIT>""" <EOL> libnames = dict . fromkeys ( [ lib . _full_name for lib in self . shlibs ] ) <EOL> pkg = '<STR_LIT:.>' . join ( ext . _full_name . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] + [ '<STR_LIT>' ] ) <EOL> return any ( pkg + libname in libnames for libname in ext . libraries ) <EOL> def get_outputs ( self ) : <EOL> return _build_ext . get_outputs ( self ) + self . __get_stubs_outputs ( ) <EOL> def __get_stubs_outputs ( self ) : <EOL> ns_ext_bases = ( <EOL> os . path . join ( self . build_lib , * ext . _full_name . split ( '<STR_LIT:.>' ) ) <EOL> for ext in self . extensions <EOL> if ext . _needs_stub <EOL> ) <EOL> pairs = itertools . product ( ns_ext_bases , self . __get_output_extensions ( ) ) <EOL> return list ( base + fnext for base , fnext in pairs ) <EOL> def __get_output_extensions ( self ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> if self . get_finalized_command ( '<STR_LIT>' ) . optimize : <EOL> yield '<STR_LIT>' <EOL> def write_stub ( self , output_dir , ext , compile = False ) : <EOL> log . info ( "<STR_LIT>" , ext . _full_name , <EOL> output_dir ) <EOL> stub_file = ( os . path . join ( output_dir , * ext . _full_name . split ( '<STR_LIT:.>' ) ) + <EOL> '<STR_LIT>' ) <EOL> if compile and os . path . exists ( stub_file ) : <EOL> raise DistutilsError ( stub_file + "<STR_LIT>" ) <EOL> if not self . dry_run : <EOL> f = open ( stub_file , '<STR_LIT:w>' ) <EOL> f . write ( <EOL> '<STR_LIT:\n>' . join ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" + if_dl ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % os . path . basename ( ext . _file_name ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> if_dl ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> if_dl ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> if_dl ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> ) <EOL> f . close ( ) <EOL> if compile : <EOL> from distutils . util import byte_compile <EOL> byte_compile ( [ stub_file ] , optimize = <NUM_LIT:0> , <EOL> force = True , dry_run = self . dry_run ) <EOL> optimize = self . get_finalized_command ( '<STR_LIT>' ) . optimize <EOL> if optimize > <NUM_LIT:0> : <EOL> byte_compile ( [ stub_file ] , optimize = optimize , <EOL> force = True , dry_run = self . dry_run ) <EOL> if os . path . exists ( stub_file ) and not self . dry_run : <EOL> os . unlink ( stub_file ) <EOL> if use_stubs or os . name == '<STR_LIT>' : <EOL> def link_shared_object ( <EOL> self , objects , output_libname , output_dir = None , libraries = None , <EOL> library_dirs = None , runtime_library_dirs = None , export_symbols = None , <EOL> debug = <NUM_LIT:0> , extra_preargs = None , extra_postargs = None , build_temp = None , <EOL> target_lang = None ) : <EOL> self . link ( <EOL> self . SHARED_LIBRARY , objects , output_libname , <EOL> output_dir , libraries , library_dirs , runtime_library_dirs , <EOL> export_symbols , debug , extra_preargs , extra_postargs , <EOL> build_temp , target_lang <EOL> ) <EOL> else : <EOL> libtype = '<STR_LIT>' <EOL> def link_shared_object ( <EOL> self , objects , output_libname , output_dir = None , libraries = None , <EOL> library_dirs = None , runtime_library_dirs = None , export_symbols = None , <EOL> debug = <NUM_LIT:0> , extra_preargs = None , extra_postargs = None , build_temp = None , <EOL> target_lang = None ) : <EOL> assert output_dir is None <EOL> output_dir , filename = os . path . split ( output_libname ) <EOL> basename , ext = os . path . splitext ( filename ) <EOL> if self . library_filename ( "<STR_LIT:x>" ) . startswith ( '<STR_LIT>' ) : <EOL> basename = basename [ <NUM_LIT:3> : ] <EOL> self . create_static_lib ( <EOL> objects , basename , output_dir , debug , target_lang <EOL> ) </s>
