3 Pf~@s$dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZddlmZddlZddlmZddlmZmZdd lmZmZm Z dd l!m"Z"m#Z#dd lm$Z$dd l%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8dZ9d9Z:ej;e<Z=Gddde>Z?ddZ@ddZAd;ddZBd d!ZCd"d#ZDe jEd$e jFZGd%d&ZHd'd(ZIdZOGd7d8d8e>ZPdS)=zH Support for installing and building the "wheel" binary package format. )absolute_importN)urlsafe_b64encode)Parser)StringIO) expanduser) path_to_url unpack_url)InstallationErrorInvalidWheelFilenameUnsupportedWheel)distutils_schemePIP_DELETE_MARKER_FILENAME) pep425tags)call_subprocess ensure_dircaptured_stdoutrmtree read_chunks) open_spinner) indent_log)SETUPTOOLS_SHIM) ScriptMaker) pkg_resources)canonicalize_name) configparserz.whlc@s eZdZdZddZddZdS) WheelCachez&A cache of wheels for future installs.cCs|r t|nd|_||_dS)zCreate a wheel cache. :param cache_dir: The root of the cache. :param format_control: A pip.index.FormatControl object to limit binaries being read from the cache. N)r _cache_dir_format_control)self cache_dirformat_controlr"/usr/lib/python3.6/wheel.py__init__8szWheelCache.__init__cCst|j||j|S)N) cached_wheelrr)rlink package_namer"r"r#r%BszWheelCache.cached_wheelN)__name__ __module__ __qualname____doc__r$r%r"r"r"r#r5s rcCs|jg}|jdk r4|jdk r4|jdj|j|jgdj|}tj|jj}|dd|dd|dd|ddg}t j j|df|S)a Return a directory to store cached wheels in for link. Because there are M wheels for any one sdist, we provide a directory to cache them in, and then consult that directory when looking up cache hits. We only insert things into the cache if they have plausible version numbers, so that we don't contaminate the cache with things that were not unique. E.g. ./package might have dozens of installs done for it and build a version of 0.0...and if we built and cached a wheel, we'd end up using the same wheel even if the source has been edited. :param cache_dir: The cache_dir being used by pip. :param link: The link of the sdist for which this will cache wheels. N=#Zwheels) Zurl_without_fragmentZ hash_namehashappendjoinhashlibZsha224encodeZ hexdigestospath)r r&Z key_partsZkey_urlZhashedpartsr"r"r#_cache_for_linkGs ,r9c Cs,|s|S|s|S|jr|S|js$|S|s,|St|}tjj||}d|krN|St||}ytj|}Wn:t k r}z|j t j t j fkr|SWYdd}~XnXg} xL|D]D} y t | } Wntk rwYnX| jsq| j| j| fqW| s|S| jtjj|| dd} tjjt| S)Nbinaryrr)is_wheel is_artifactrpipindexfmt_ctl_formatsr9r6listdirOSErrorerrnoENOENTENOTDIRWheelr supportedr2support_index_minsortr7r3Linkr) r r&r!r'Zcanonical_nameZformatsrootZ wheel_nameseZ candidates wheel_namewheelr7r"r"r#r%psF   r%sha256c Csttj|}d}t|d2}x*t||dD]}|t|7}|j|q(WWdQRXdt|jjdj d}||fS)z6Return (hash, length) for path using hashlib.new(algo)rrb)sizeNzsha256=latin1r,) r4newopenrlenupdaterdigestdecoderstrip)r7ZalgoZ blocksizehZlengthfblockrWr"r"r#rehashs    r]cCs6tjddkri}d}n ddi}d}t|||f|S)Nrbnewline)sys version_inforT)namemodenlbinr"r"r# open_for_csvs rhcCstjj|rt|dH}|j}|jds.dStjjtj }d|tj jd}|j }WdQRXt|d}|j ||j |WdQRXdSdS) zLReplace #!python with #!/path/to/python Return True if file was changed.rPs#!pythonFs#!asciiNwbT) r6r7isfilerTreadline startswithrb executabler5getfilesystemencodinglinesepreadwrite)r7Zscript firstlineZexenamerestr"r"r# fix_scripts     ruzZ^(?P(?P.+?)(-(?P\d.+?))?) \.dist-info$c Cs|jdd}xttj|D]f}tj|}|r|jd|krttjj||d,}x$|D]}|j j }|dkrTdSqTWWdQRXqWdS) zP Return True if the extracted wheel in wheeldir should go into purelib. -_rdWHEELzroot-is-purelib: trueTNF) replacer6r@ dist_info_rematchgrouprTr7r3lowerrY)rdwheeldirZ name_foldeditemr{rMliner"r"r#root_is_purelibs    rc Cstjj|siifSt|<}t}x$|D]}|j|j|jdq*W|jdWdQRXtj }dd|_ |j |i}i}|j drt |jd}|j drt |jd}||fS)N rcSs|S)Nr")Zoptionr"r"r#sz!get_entrypoints..Zconsole_scriptsZ gui_scripts)r6r7existsrTrrrstripseekrZRawConfigParserZ optionxformZreadfpZ has_sectiondictitems)filenamefpdatarZcpconsoleguir"r"r#get_entrypointss$       rFTc +)s*|st|||||| d}t| r,|dn|dgg jtjjtjj} itg} |rt4} tj tj dt j | dddWdQRXWdQRXt j| jdd d3 fd d d4 fd d }|| dstd tjjdd}t|\fdd}xvD]n}d}d}x^tjtjj |D]F}d}|dkrpt}|}tjj ||} ||}|| |d ||dqVWq4Wtd|dd_td5_d_ fdd}|_d_jdd}|rdtjkrd|}| jj|tjjdddkrTdt j!dd|f}| jj|dt j!dd |f}| jj|d!d"D}x|D] }|=qWjd#d}|rdtjkrd$|}| jj|d%t j!dd |f}| jj|d&d"D}x|D] }|=qWt"dkrJ| jj#d'd"j$Dt"dkr|| jj#d(d"j$Dd)ditjjdd*}tjjdd+}t%|d,}|j&d-WdQRXt'j(||| j)|tjjdd.} tjjdd/}!t*| d0}"t*|!d1}#t+j,|"}$t+j-|#}%xV|$D]N}&j|&d|&d|&d<|&dkrpt.|&d\|&d<|&d2<|%j/|&q.Wx`| D]X}'t.|'\}(})|'}*| r|*j0| rtjjtjtjj1|*| }*|%j/|*|(|)fqWx"D]}'|%j/|'ddfqWWdQRXWdQRXt'j(|!| dS)6zInstall a wheel)userhomerJisolatedprefixpurelibplatlibignoreT)forcequietNcSstjj||jtjjdS)N/)r6r7relpathrysep)srcpr"r"r#normpathsz"move_wheel_files..normpathFcs.|}|}||<|r*j|dS)z6Map archive RECORD paths to installation RECORD paths.N)add)srcfiledestfileZmodifiedZoldpathnewpath)changed installedlib_dirrr~r"r#record_installeds   z*move_wheel_files..record_installedcst|xtj|D]\}}}|t|djtjj}tjj||} |rj|jtjjddj drjqx|D]} tjj||| } |r|dkr| j drj | qpqp|rp| j drpt | j t j rp std| ddjj | qpWx|D]} |r|| rqtjj|| } tjj||| }t| tj| |tj| }ttdrptj||j|jftj| tjrtj| }|jtjBtjBtjB}tj||d }|r||}| ||qWqWdS) Nrrz.dataraz .dist-infoz!Multiple .dist-info directories: z, utimeF)rr6walkrUlstripr7rr3splitendswithr2rrmrdAssertionErrorshutilZcopyfilestathasattrrst_atimest_mtimeaccessX_OKst_modeS_IXUSRS_IXGRPS_IXOTHchmod)sourcedestZis_basefixerfilterdirZsubdirsfilesZbasedirZdestdirsZ destsubdirr[rrstZ permissionsr) data_dirsinfo_dirrreqr"r#clobbersJ           z!move_wheel_files..clobberz!%s .dist-info directory not foundrzentry_points.txtcsh|jjdr|dd}n<|jjdr8|dd}n |jjdrT|dd}n|}|kpf|kS) Nz.exer/z -script.py z.pyair)r}r)rdZ matchname)rrr"r#is_entrypoint_wrapperasz/move_wheel_files..is_entrypoint_wrapperscripts)rrracs<|jdkrtd|fj|j|jjdd|jdS)NzInvalid script entry point: %s for req: %s - A callable suffix is required. Cf https://packaging.python.org/en/latest/distributing.html#console-scripts for more information..r)moduleZ import_namefunc)suffixr script_templaterr)entry)makerrr"r#_get_script_texts  z*move_wheel_files.._get_script_textz# -*- coding: utf-8 -*- import re import sys from %(module)s import %(import_name)s if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(%(func)s()) r=ZENSUREPIP_OPTIONSzpip = Z altinstallz pip%s = %srr^cSsg|]}tjd|r|qS)zpip(\d(\.\d)?)?$)rer{).0kr"r"r# sz$move_wheel_files..Z easy_installzeasy_install = zeasy_install-%s = %scSsg|]}tjd|r|qS)zeasy_install(-\d\.\d)?$)rr{)rrr"r"r#rscSsg|] }d|qS)z%s = %sr")rkvr"r"r#rscSsg|] }d|qS)z%s = %sr")rrr"r"r#rsrZ INSTALLERz INSTALLER.piprjspip RECORDz RECORD.piprzw+r.)F)NN)ra)2r rrYr6r7rsetrwarningscatch_warningsfilterwarnings compileall compile_dirloggerdebuggetvaluerr3rr@rurrZvariantsZset_moderrpopenvironextendZmakegetrbversionrUZ make_multiplerrTrrrmover2rhcsvreaderwriterr]Zwriterowrmr)+rdrr~rrrJZ pycompileschemerrZstrip_file_prefixrZ generatedstdoutrZep_filerZdatadirrrZsubdirrrZ pip_scriptspecZpip_eprZeasy_install_scriptZeasy_install_epZ installerZtemp_installerZinstaller_filerecordZ temp_recordZ record_inZ record_outrrrowr[rZlZ final_pathr") rrrrrrrrrrrr~r#move_wheel_filess     $;      #                     .rcstjfdd}|S)Nc?s6t}x*||D]}||kr|j||VqWdS)N)rr)argskwseenr)fnr"r#uniques  z_unique..unique) functoolswraps)rrr")rr#_uniquesrccsddlm}tj||jd}xd|D]\}tjj|j|d}|V|j dr&tjj |\}}|dd}tjj||d}|Vq&WdS) a Yield all the uninstallation paths for dist based on RECORD-without-.pyc Yield paths to all the files in RECORD. For each .py file in RECORD, add the .pyc in the same directory. UninstallPathSet.add() takes care of the __pycache__ .pyc. r)FakeFilerz.pyNr^z.pyc) pip.utilsrrrZget_metadata_linesr6r7r3locationrr)distrrrr7Zdnrbaser"r"r#uninstallation_paths"s    rc CsdyTddtjd|Dd}|jd}tj|}|dj}ttt|j d}|SdSdS) z Return the Wheel-Version of an extracted wheel, if possible. Otherwise, return False if we couldn't parse / extract it. cSsg|]}|qSr"r")rdr"r"r#r?sz!wheel_version..Nrrxz Wheel-VersionrF) rZ find_on_pathZ get_metadatarZparsestrrtuplemapintr) source_dirrZ wheel_datarr"r"r# wheel_version8s   rcCsb|std||dtdkr>td|djtt|fn |tkr^tjddjtt|dS)a Raises errors or warns if called with an incompatible Wheel-Version. Pip should refuse to install a Wheel-Version that's a major series ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when installing a version only minor version ahead (e.g 1.2 > 1.1). version: a 2-tuple representing a Wheel-Version (Major, Minor) name: name of wheel or package to raise exception about :raises UnsupportedWheel: when an incompatible Wheel-Version is given z(%s is in an unsupported or invalid wheelrzB%s's Wheel-Version (%s) is not compatible with this version of piprz*Installing from a newer Wheel-Version (%s)N)r VERSION_COMPATIBLEr3rstrrwarning)rrdr"r"r#check_compatibilityKs  rc@s:eZdZdZejdejZddZd ddZ d dd Z dS) rEz A wheel filez^(?P(?P.+?)-(?P\d.*?)) ((-(?P\d.*?))?-(?P.+?)-(?P.+?)-(?P.+?) \.whl|\.dist-info)$csjj|}|std||_|jdjdd_|jdjdd_|jdjd_ |jdjd_ |jd jd_ t fd d j D_ d S) zX :raises InvalidWheelFilename: when the filename is invalid for a wheel z!%s is not a valid wheel filename.rdrwrvZverZpyverrabiZplatc3s0|](}jD]}jD]}|||fVqq qdS)N)abisplats)rxyz)rr"r# sz!Wheel.__init__..N) wheel_file_rer{r rr|ryrdrrZ pyversionsr r r file_tags)rrZ wheel_infor")rr#r$ts  zWheel.__init__Ncs2dkrtjfdd|jD}|r.t|SdS)a" Return the lowest index that one of the wheel's file_tag combinations achieves in the supported_tags list e.g. if there are 8 supported tags, and one of the file tags is first in the list, then return 0. Returns None is the wheel is not supported. Ncsg|]}|krj|qSr")r>)rc)tagsr"r#rsz+Wheel.support_index_min..)rsupported_tagsrmin)rrZindexesr")rr#rGszWheel.support_index_mincCs"|dkrtj}tt|j|jS)z'Is this wheel supported on this system?N)rrboolr intersectionr)rrr"r"r#rFszWheel.supported)N)N) r(r)r*r+rcompileVERBOSErr$rGrFr"r"r"r#rEhs rEc@sHeZdZdZdddZdddZddZdd d Zd d ZdddZ dS) WheelBuilderz#Build wheels from a RequirementSet.NcCs6||_||_|jj|_|j|_|p$g|_|p.g|_dS)N) requirement_setfinderZ _wheel_cacher _cache_rootZwheel_download_dir _wheel_dir build_optionsglobal_options)rrrrr r"r"r#r$s   zWheelBuilder.__init__cCstjd}zn|j|||drlyBtj|d}tjj||}tjtjj|||t j d||SYnX|j |dSt |XdS)ziBuild one wheel. :return: The filename of the built wheel, or None if the build failed. z pip-wheel-) python_tagrzStored in directory: %sN) tempfileZmkdtemp_WheelBuilder__build_oner6r@r7r3rrrinfo _clean_oner)rr output_dirr!tempdrLZ wheel_pathr"r"r# _build_ones   zWheelBuilder._build_onecCstjddt|jgt|jS)Nz-uz-c)rbrnrZsetup_pylistr )rrr"r"r#_base_setup_argss zWheelBuilder._base_setup_argscCs|j|}d|jf}t|t}tjd||dd|g|j}|dk rT|d|g7}yt||jd|ddS|jd tj d |jdSWdQRXdS) Nz#Running setup.py bdist_wheel for %szDestination directory: %sZ bdist_wheelz-dz --python-tagF)cwd show_stdoutspinnerTerrorzFailed building wheel for %s) r*rdrrrrrZ setup_py_dirZfinishr.)rrr'r! base_argsZ spin_messager-Z wheel_argsr"r"r#Z __build_ones       zWheelBuilder.__build_onec CsV|j|}tjd|j|ddg}yt||jdddStjd|jdSdS)NzRunning setup.py clean for %sZcleanz--allF)r+r,Tz Failed cleaning build dir for %s)r*rr$rdrrr.)rrr/Z clean_argsr"r"r#r%s  zWheelBuilder._clean_oneFcCs|js|r|jst|jj|j|jjj}g}x|D]}|jrDq8|j r^|st j d|j q8|rj|j rjq8|r|jr|jj rq8|r|j rq8|r|j}|j\}}tjj|d|dkrq8dtjj|jjt|j krt j d|j q8|j|q8W|sdSt j ddjdd |DtJgg}} x6|D],}d} |rtj} t|j|j} y t| WnBtk r} z$t j d |j | | j|w6WYdd} ~ XnXn|j} |j!|| | d } | rX|j||rb|jrt"j#j$t"j#j|jt% rtd |j&|j'|jj(|_tjj)t*| |_|jj s.z Building wheel for %s failed: %s)r!zbad source dir - missing markerF)sessionzSuccessfully built %s cSsg|] }|jqSr")rd)rrr"r"r#rQszFailed to build %scSsg|] }|jqSr")rd)rrr"r"r#rVsr).rrrrZ prepare_filesrZ requirementsvaluesZ constraintr;rr$rdZeditabler&r<rsplitextr=r>Zegg_info_matchesr?r!rr2r3rrZimplementation_tagr9rrArr(r6r7rr Zremove_temporary_sourceZbuild_locationZ build_dirrIrrr0rU)rZ autobuildingZreqsetZbuildsetrr&rZextZ build_successZ build_failurer!r&rKZ wheel_filer"r"r#builds               zWheelBuilder.build)NN)N)N)F) r(r)r*r+r$r(r*r#r%r4r"r"r"r#rs    r)rr)rNr5)FNNTNFNN)Qr+Z __future__rrrrBrr4Zloggingr6Zos.pathrrrrbr"rbase64rZ email.parserrZpip._vendor.sixrr=Z pip.compatrZ pip.downloadrrZpip.exceptionsr r r Z pip.locationsr r rrrrrrrZ pip.utils.uirZpip.utils.loggingrZpip.utils.setuptools_buildrZpip._vendor.distlib.scriptsrZ pip._vendorrZpip._vendor.packaging.utilsrZpip._vendor.six.movesrZ wheel_extrZ getLoggerr(robjectrr9r%r]rhrurrrzrrrrrrrrErr"r"r"r#sn              )'    ' 7