a (Re3 @spddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZddlmZdd lmZzddlmZed WneyeZYn0ed dd l mZd dZdZdZdZejdkrdZnsr!cCs.tD]$}d|vr|S|dkr|SqdS)z;Return the file extension for an abi3-compliant Extension()z.abi3z.pydNr)suffixrrrget_abi3_suffixBs r#c@sveZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdddZdS)rcCs.|jd}|_t|||_|r*|dS)z;Build extensions in build directory, then copy if --inplacerN)Zinplace _build_extruncopy_extensions_to_source)selfZ old_inplacerrrr%Ls  z build_ext.runc Cs|d}|jD]}||j}||}|d}d|dd}||}tj |tj |}tj |j |} t | ||j |jd|jr||ptj|dqdS)Nbuild_py.)verbosedry_runT)get_finalized_command extensionsget_ext_fullnamenameget_ext_filenamesplitjoinZget_package_dirospathbasename build_librr+r, _needs_stub write_stubcurdir) r'r(extfullnamefilenamemodpathpackage package_dirZ dest_filenameZ src_filenamerrrr&Ts"       z#build_ext.copy_extensions_to_sourcecCstd}|r&tjj|d|}nt||}td}||jvr|j|}t |do\t }|r|dt | }t }||}t |t rtj|\}}|j|tStr|jrtj|\}}tj|d|S|S)NZSETUPTOOLS_EXT_SUFFIXr) EXT_SUFFIXZpy_limited_apizdl-)r4getenvr5r3r2r$r1rext_mapgetattrr#len isinstancer splitextshlib_compilerlibrary_filenamelibtype use_stubs_links_to_dynamic)r'r<Zso_extr=r;Zuse_abi3fndrrrr1js&      zbuild_ext.get_ext_filenamecCs t|d|_g|_i|_dSN)r$initialize_optionsrHshlibsrCr'rrrrPs zbuild_ext.initialize_optionscCs,t||jpg|_||jdd|jD|_|jrB||jD]}||j|_qH|jD]}|j}||j |<||j | dd<|jr| |pd}|ot ot |t }||_||_||}|_tjtj|j|}|r||jvr|j||rbt rbtj|jvrb|jtjqbdS)NcSsg|]}t|tr|qSr)rFr .0r;rrr s z.build_ext.finalize_options..r)r*F)r$finalize_optionsr.Zcheck_extensions_listrQsetup_shlib_compilerr/r0 _full_namerCr2links_to_dynamicrKrFr rLr8r1 _file_namer4r5dirnamer3r7 library_dirsappendr:runtime_library_dirs)r'r;r<Zltdnsr=libdirrrrrVs,       zbuild_ext.finalize_optionscCst|j|j|jd}|_t||jdur8||j|jdur^|jD]\}}| ||qH|j dur~|j D]}| |qn|j dur| |j |jdur||j|jdur||j|jdur||jt||_dS)N)rr,force)rrr,rarHr include_dirsZset_include_dirsZdefineZ define_macroZundefZundefine_macro librariesZ set_librariesr\Zset_library_dirsZrpathZset_runtime_library_dirsZ link_objectsZset_link_objectslink_shared_object__get__)r'rr0valueZmacrorrrrWs*               zbuild_ext.setup_shlib_compilercCst|tr|jSt||SrO)rFr export_symbolsr$get_export_symbolsr'r;rrrrhs zbuild_ext.get_export_symbolscCsb||j}zFt|tr"|j|_t|||jrL|dj }| ||W||_n||_0dS)Nr() Z_convert_pyx_sources_to_langrrFr rHr$build_extensionr8r-r7r9)r'r;Z _compilercmdrrrrjs   zbuild_ext.build_extensioncsPtdd|jDd|jddddgtfdd|jDS) z?Return true if 'ext' links to a dynamic lib in the same packagecSsg|] }|jqSr)rX)rTlibrrrrUz.build_ext.links_to_dynamic..r)Nr*rc3s|]}|vVqdSrOr)rTZlibnameZlibnamespkgrr rmz-build_ext.links_to_dynamic..)dictfromkeysrQr3rXr2anyrcrirrnrrYs zbuild_ext.links_to_dynamiccCst||SrO)r$ get_outputs_build_ext__get_stubs_outputsrRrrrrtszbuild_ext.get_outputscs6fddjD}t|}tdd|DS)Nc3s2|]*}|jrtjjjg|jdRVqdS)r)N)r8r4r5r3r7rXr2rSrRrrrpsz0build_ext.__get_stubs_outputs..css|]\}}||VqdSrOr)rTbaseZfnextrrrrprm)r. itertoolsproduct!_build_ext__get_output_extensionslist)r'Z ns_ext_basespairsrrRrZ__get_stubs_outputss  zbuild_ext.__get_stubs_outputsccs"dVdV|djrdVdS)N.pyz.pycr(z.pyo)r-optimizerRrrrZ__get_output_extensionss z!build_ext.__get_output_extensionsFcCs4td|j|tjj|g|jdRd}|rLtj|rLt|d|j st |d}| dddd t d d tj |jd d dt ddddt ddddddt ddddg||r0ddlm}||gdd|j d |d!j}|dkr||g|d|j d tj|r0|j s0t|dS)"Nz writing stub loader for %s to %sr)r|z already exists! Please delete.w zdef __bootstrap__():z- global __bootstrap__, __file__, __loader__z0 import sys, os, pkg_resources, importlib.utilz, dlz: __file__ = pkg_resources.resource_filename(__name__,%r)z del __bootstrap__z if '__loader__' in globals():z del __loader__z# old_flags = sys.getdlopenflags()z old_dir = os.getcwd()z try:z( os.chdir(os.path.dirname(__file__))z$ sys.setdlopenflags(dl.RTLD_NOW)z3 spec = importlib.util.spec_from_file_location(z# __name__, __file__)z0 mod = importlib.util.module_from_spec(spec)z! spec.loader.exec_module(mod)z finally:z" sys.setdlopenflags(old_flags)z os.chdir(old_dir)z__bootstrap__()rr) byte_compileT)r}rar, install_lib)r inforXr4r5r3r2existsr r,openwriter!r6rZclosedistutils.utilrr-r}unlink)r' output_dirr;compileZ stub_filefrr}rrrr9sh       zbuild_ext.write_stubN)F)__name__ __module__ __qualname__r%r&r1rPrVrWrhrjrYrtruryr9rrrrrKs   rc Cs(||j||||||||| | | | dSrO)linkZSHARED_LIBRARY) r'objectsoutput_libnamerrcr\r^rgdebug extra_preargsextra_postargs build_temp target_langrrrrd$s rdZstaticc Cs^|dus Jtj|\}} tj| \}}|ddrH|dd}|||||| dS)Nxrl)r4r5r2rGrI startswithZcreate_static_lib)r'rrrrcr\r^rgrrrrrr=r6r;rrrrd3s   ) NNNNNrNNNN) NNNNNrNNNN)&r4rrwimportlib.machineryrZdistutils.command.build_extrZ _du_build_extdistutils.file_utilrdistutils.ccompilerrdistutils.sysconfigrrdistutils.errorsr distutilsr Zsetuptools.extensionr ZCython.Distutils.build_extr$ __import__ ImportErrorr rrrrKrJrr0dlhasattrr!r#rdrrrrsZ               W