o _a@@s"dZddlmZmZddlmZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl mZmZmZddlmZddlmZdd lmZmZd d Zd d ZddZddZGdddeZedZ ddZ!ddZ"ddZ#dddZ$ddZ%d d!Z&d"d#Z'gd$Z( % &d)d'd(Z)dS)*z6setuptools.command.bdist_egg Build .egg distributions) remove_treemkpath)log)CodeTypeN)get_build_platform Distributionensure_directory)Library)Command)get_pathget_python_versioncCstdS)Npurelib)r rr>/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py _get_purelibrcCs2d|vr tj|d}|dr|dd}|S)N.rmodulei)ospathsplitextendswith)filenamerrr strip_modules   rccs8t|D]\}}}|||||fVqdS)zbDo os.walk in a reproducible way, independent of indeterministic filesystem readdir order N)rwalksort)dirbasedirsfilesrrr sorted_walk!s r cCsLtd}t|d}|||WddS1swYdS)Na def __bootstrap__(): global __bootstrap__, __loader__, __file__ import sys, pkg_resources, importlib.util __file__ = pkg_resources.resource_filename(__name__, %r) __loader__ = None; del __bootstrap__, __loader__ spec = importlib.util.spec_from_file_location(__name__,__file__) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) __bootstrap__() w)textwrapdedentlstripopenwrite)resourcepyfile_stub_templatefrrr write_stub+s   "r+c@seZdZdZddddefdddd gZgd Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZdd Zd!S)" bdist_eggzcreate an "egg" distribution)z bdist-dir=bz1temporary directory for creating the distributionz plat-name=pz;platform name to embed in generated filenames (default: %s))exclude-source-filesNz+remove all .py files from the generated egg) keep-tempkzPkeep the pseudo-installation tree around after creating the distribution archive)z dist-dir=dz-directory to put final built distributions in) skip-buildNz2skip rebuilding everything (for testing/debugging))r0r3r/cCs.d|_d|_d|_d|_d|_d|_d|_dS)Nr) bdist_dir plat_name keep_tempdist_dir skip_build egg_outputexclude_source_filesselfrrrinitialize_optionsRs zbdist_egg.initialize_optionscCs|d}|_|j|_|jdur|dj}tj|d|_|jdur(t |_| dd|j durTt dd|j |jt|joC|j }tj|j|d|_ dSdS)Negg_infobdistegg)r7r7z.egg)get_finalized_commandei_cmdr>r4 bdist_baserrjoinr5rset_undefined_optionsr9regg_name egg_versionr distributionhas_ext_modulesr7)r<rBrCbasenamerrrfinalize_options[s$      zbdist_egg.finalize_optionscCs|j|d_tjtjt}|jj g}|j_ |D]D}t |t rZt |dkrZtj |drZtj|d}tj|}||ksL||tjrZ|t |dd|df}|jj |qztd|j|jddddW||j_ dS||j_ w)Ninstallrzinstalling package data to %s install_data)forceroot)r4rA install_librrnormcaserealpathrrH data_files isinstancetuplelenisabs startswithsepappendrinfo call_command)r< site_packagesolditemrT normalizedrrrdo_install_datass"  zbdist_egg.do_install_datacCs|jgS)N)r9r;rrr get_outputsrzbdist_egg.get_outputscKsTtD] }|||jq|d|j|d|j|j|fi|}|||S)z8Invoke reinitialized command `cmdname` with keyword argsr8dry_run)INSTALL_DIRECTORY_ATTRS setdefaultr4r8rereinitialize_command run_command)r<cmdnamekwdirnamecmdrrrr^s zbdist_egg.call_commandcCs|dtd|j|d}|j}d|_|jr$|js$|d|j ddd}||_| \}}g|_ g}t |D]>\}}t j|\} } t j|jt| d} |j | td ||jsmtt j|| || |t jd ||<q=|r|||jjr||j} t j| d } || |jjrt j| d }td ||j d|dd|| t j| d}|rtd||jst|t|d}| d|| d|!nt j"|rtd||jst #|t$t j| d |%t j&t j|j'drt(d|j)r|*t+|j,| |j-|j|.d|j/s9t0|j|jdt1|jdgdt2|j,fdS)Nr>zinstalling library code to %srL build_clibrRr)warn_dir.pyzcreating stub loader for %s/EGG-INFOscriptszinstalling scripts to %sinstall_scriptsrN) install_dirno_epznative_libs.txtz writing %swt z removing %sz depends.txtzxWARNING: 'depends.txt' will not be used by setuptools 0.6! Use the install_requires/extras_require setup() args instead.)verboseremodere dist_filesr,)3rirr]r4rArQrHhas_c_librariesr8r^get_ext_outputsstubs enumeraterrrrDrr\rer+rJreplacer[ byte_compilerUrcrrscopy_metadata_torr%r&closeisfileunlinkwrite_safety_flagzip_safeexistsr>warnr: zap_pyfiles make_zipfiler9ry gen_headerr6rgetattrr )r<instcmdold_rootrm all_outputs ext_outputs to_compiler.ext_namerextr( archive_rootr> script_dir native_libs libs_filerrrruns                    z bdist_egg.runc Cstdt|jD]^\}}}|D]V}tj||}|dr*td|t ||drg|}d}t ||}tj|tj | dd} td|| fzt| Wn ty`Ynwt|| qq dS) Nz+Removing .py files from temporary directoryrpz Deleting %s __pycache__z#(?P.+)\.(?P[^.]+)\.pycname.pyczRenaming file from [%s] to [%s])rr]walk_eggr4rrrDrdebugrrematchpardirgroupremoveOSErrorrename) r<rrrrrpath_oldpatternmpath_newrrrrs8        zbdist_egg.zap_pyfilescCs2t|jdd}|dur |Stdt|j|jS)Nrz4zip_safe flag not set; analyzing archive contents...)rrHrr analyze_eggr4r)r<saferrrrs  zbdist_egg.zip_safecCsdS)Nr!rr;rrrr szbdist_egg.gen_headercCshtj|j}tj|d}|jjjD]}||r1tj||t |d}t || ||qdS)z*Copy metadata (egg info) to the target_dirN) rrnormpathr>rDrBfilelistrrZrXr copy_file)r< target_dir norm_egg_infoprefixrtargetrrrrs  zbdist_egg.copy_metadata_toc Csg}g}|jdi}t|jD]3\}}}|D]}tj|dtvr,||||q|D]}|||d|tj||<q/q|j r}| d}|j D]-} t | trWqO|| j} || }tj|ds|tjtj|j|r|||qO||fS)zAGet a list of relative paths to C extensions in the output distrorrNrq build_extzdl-)r4r rrrlowerNATIVE_EXTENSIONSr\rDrHrIrA extensionsrVr get_ext_fullnamerget_ext_filenamerJrZr) r<rrpathsrrrr build_cmdrfullnamerrrr~s6        zbdist_egg.get_ext_outputsN)__name__ __module__ __qualname__ descriptionr user_optionsboolean_optionsr=rKrcrdr^rrrrrr~rrrrr,;s.  Q r,z.dll .so .dylib .pydccsJt|}t|\}}}d|vr|d|||fV|D]}|VqdS)z@Walk an unpacked egg's contents, skipping the metadata directoryrrN)r nextr)egg_dirwalkerrrrbdfrrrr:s  rc CstD]\}}tjtj|d|r|SqtsdSd}t|D](\}}}|D] }|ds7|dr8q+|dsB|drKt ||||oJ|}q+q$|S)NrrFTrpz.pywrz.pyo) safety_flagsitemsrrrrDcan_scanrr scan_module) rrflagfnrrrrrrrrrEs rcCstD]9\}}tj||}tj|r%|dust||kr$t|q|dur=t||kr=t|d}| d| qdS)Nrwrx) rrrrrDrboolrr%r&r)rrrrr*rrrrWs    rzzip-safez not-zip-safe)TFc Cstj||}|dd|vrdS|t|ddtjd}||r%dp&dtj|d}tjdkr8d }nd }t |d }| |t |} | d} tt| } d D]} | | vrgtd || d} qXd| vr~dD]} | | vr}td|| d} qn| S)z;Check whether module possibly uses unsafe-for-zipfile stuffNTrNrrr) rb)__file____path__z%s: module references %sFinspect) getsource getabsfile getsourcefilegetfilegetsourcelines findsource getcomments getframeinfogetinnerframesgetouterframesstacktracez"%s: module MAY be using inspect.%s)rrrDrXrr[rsys version_infor%readmarshalloadrdictfromkeys iter_symbolsrr) rrrrrpkgrskipr*codersymbolsbadrrrrjs4     rccsT|jD]}|Vq|jD]}t|tr|Vq t|tr't|D]}|Vq!q dS)zBYield names and strings used by `code` and its nested code objectsN)co_names co_constsrVstrrr)rrconstrrrrs     rcCs2tjds tjdkr dStdtddS)NjavacliTz1Unable to analyze compiled code on this platform.zfPlease ask the author to include a 'zip_safe' setting (either True or False) in the package's setup.py)rplatformrZrrrrrrrs r)rRrurO install_baseTr!c sddl}ttj|dtd|fdd}|r!|jn|j}sD|j |||d} t D] \} } } || | | q2| |St D] \} } } |d| | qH|S)aqCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_dir' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises DistutilsExecError. Returns the name of the output zip file. rNr{z#creating '%s' and adding '%s' to itcs`|D]+}tjtj||}tj|r-|tdd}s'|||td|qdS)NrNz adding '%s') rrrrDrrXr&rr)zrlnamesrrr.base_dirrerrvisits   zmake_zipfile..visit) compression) zipfilerrrrlrr] ZIP_DEFLATED ZIP_STOREDZipFiler r) zip_filenamerryrecompressrzrrrrrlrrrrrrs r)rrTr!)*__doc__distutils.dir_utilrr distutilsrtypesrrrrr"r pkg_resourcesrrrsetuptools.extensionr setuptoolsr sysconfigr r rrr r+r,rrsplitrrrrrrrrrfrrrrrsB     } "