3 ] }@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"(/tmp/pip-build-8jg9gmni/pip/pip/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=#wheels) url_without_fragment hash_namehashappendjoinhashlibsha224encode hexdigestospath)r r& key_partskey_urlhashedpartsr"r"r#_cache_for_linkGs ,rAc 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_formatsrAr;listdirOSErrorerrnoENOENTENOTDIRWheelr supportedr5support_index_minsortr<r6Linkr) r r&r!r'canonical_nameformatsroot wheel_namese candidates wheel_namewheelr<r"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,) r7newopenrlenupdaterdigestdecoderstrip)r<algo blocksizehlengthfblockrcr"r"r#rehashs    rlcCs6tjddkri}d}n ddi}d}t|||f|S)Nrbnewline)sys version_infor`)namemodenlbinr"r"r# open_for_csvs rwcCstjj|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.r\s#!pythonFs#!asciiNwbT) r;r<isfiler`readline startswithrq executabler9getfilesystemencodinglinesepreadwrite)r<script firstlineexenamerestr"r"r# fix_scripts     rzZ^(?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. -_rsWHEELzroot-is-purelib: trueTNF) replacer;rH dist_info_rematchgroupr`r<r6lowerre)rswheeldir name_foldeditemrrYliner"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")optionr"r"r#sz!get_entrypoints..console_scripts gui_scripts)r;r<existsr`rrstripseekrRawConfigParser optionxformreadfp has_sectiondictitems)filenamefpdatarcpconsoleguir"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<|%dkrnt.|%d\|%d<|%d2<|$j/|%q,Wx0| D](}&t.|&\}'}(|$j/|&|'|(fqWx"D]}&|$j/|&ddfqWWdQRXWdQRXt'j(| |dS)6zInstall a wheel)userhomerTisolatedprefixpurelibplatlibignoreT)forcequietNcSstjj||jtjjdS)N/)r;r<relpathrsep)srcpr"r"r#normpathsz"move_wheel_files..normpathFcs.|}|}||<|r*j|dS)z6Map archive RECORD paths to installation RECORD paths.N)add)srcfiledestfilemodifiedoldpathnewpath)changed installedlib_dirrrr"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.datarpz .dist-infoz!Multiple .dist-info directories: z, utimeF)rr;walkralstripr<rr6splitendswithr5rr|rsAssertionErrorshutilcopyfilestathasattrrst_atimest_mtimeaccessX_OKst_modeS_IXUSRS_IXGRPS_IXOTHchmod)sourcedestis_basefixerfilterdirsubdirsfilesbasedirdestdirs destsubdirrjrrst 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)rr)rs matchname)rrr"r#is_entrypoint_wrapperasz/move_wheel_files..is_entrypoint_wrapperscripts)rrrpcs<|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)module 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()) rEENSUREPIP_OPTIONSzpip = altinstallz pip%s = %srrmcSsg|]}tjd|r|qS)zpip(\d(\.\d)?)?$)rer).0kr"r"r# sz$move_wheel_files.. 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#rsr INSTALLERz INSTALLER.pipryspip RECORDz RECORD.piprzw+r.)F)NN)rp)0r rrer;r<rsetrwarningscatch_warningsfilterwarnings compileall compile_dirloggerdebuggetvaluerr6rrHrrrvariantsset_moderrpopenvironextendmakegetrqversionra make_multiplerr`rrmover5rwcsvreaderwriterrlwriterow))rsrrrrrT pycompileschemerrr generatedstdoutrep_filerdatadirrrsubdirrr pip_scriptspecpip_epreasy_install_scripteasy_install_ep installertemp_installerinstaller_filerecord temp_record record_in record_outrrrowrjrhlr") rrrrrrrrrrrrr#move_wheel_filess     $;      #                    .r,cstjfdd}|S)Nc?s6t}x*||D]}||kr|j||VqWdS)N)rr)argskwseenr)fnr"r#uniques  z_unique..unique) functoolswraps)r0r1r")r0r#_uniquesr4ccsddlm}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.pyNrmz.pyc) pip.utilsr5rrget_metadata_linesr;r<r6locationrr)distr5rr*r<dnr0baser"r"r#uninstallation_pathss    r=c 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..Nrrz Wheel-VersionrF) r find_on_path get_metadatarparsestrrtuplemapintr) source_dirr: wheel_datarr"r"r# wheel_version4s   rGcCsb|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_COMPATIBLEr6rCstrrwarning)rrsr"r"r#check_compatibilityGs  rKc@s:eZdZdZejdejZddZd ddZ d dd Z dS) rMz 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.rsrrverpyverrabiplatc3s0|](}jD]}jD]}|||fVqq qdS)N)abisplats)rxyz)rr"r# sz!Wheel.__init__..N) wheel_file_rerr rrrrsrr pyversionsrPrQr file_tags)rr wheel_infor")rr#r$ps  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")rF)rc)tagsr"r#rsz+Wheel.support_index_min..)rsupported_tagsrXmin)rr[indexesr")r[r#rOszWheel.support_index_mincCs"|dkrtj}tt|j|jS)z'Is this wheel supported on this system?N)rr\boolr intersectionrX)rr[r"r"r#rNszWheel.supported)N)N) r(r)r*r+rcompileVERBOSErVr$rOrNr"r"r"r#rMds rMc@sHeZdZdZdddZdddZddZdd d Zd d ZdddZ dS) WheelBuilderz#Build wheels from a RequirementSet.NcCs6||_||_|jj|_|j|_|p$g|_|p.g|_dS)N) requirement_setfinder _wheel_cacher _cache_rootwheel_download_dir _wheel_dir build_optionsglobal_options)rrdrerjrkr"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) tempfilemkdtemp_WheelBuilder__build_oner;rHr<r6rrrinfo _clean_oner)rr output_dirrltempdrX wheel_pathr"r"r# _build_ones   zWheelBuilder._build_onecCstjddt|jgt|jS)Nz-uz-c)rqr}rsetup_pylistrk)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: %s bdist_wheelz-dz --python-tagF)cwd show_stdoutspinnerTerrorzFailed building wheel for %s) rxrsrrrrjr setup_py_dirfinishr})rrrsrl base_args spin_messager| wheel_argsr"r"r# __build_ones       zWheelBuilder.__build_onec CsV|j|}tjd|j|ddg}yt||jdddStjd|jdSdS)NzRunning setup.py clean for %scleanz--allF)rzr{Tz Failed cleaning build dir for %s)rxrrprsrrEr})rrr clean_argsr"r"r#rqs  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)rlzbad source dir - missing markerF)sessionzSuccessfully built %s cSsg|] }|jqSr")rs)rrr"r"r#rMszFailed to build %scSsg|] }|jqSr")rs)rrr"r"r#rRsr).rirgrrd prepare_filesre requirementsvalues constraintrCrrprseditabler&rDrEsplitextrErFegg_info_matchesrGr!rr5r6rrimplementation_tagrArrIrJrur;r<rr remove_temporary_sourcebuild_location build_dirrQrrrra)r autobuildingreqsetbuildsetrr&r<ext build_success build_failurerlrrrV wheel_filer"r"r#builds               zWheelBuilder.build)NN)N)N)F) r(r)r*r+r$rurxrorqrr"r"r"r#rcs    rc)rr)rZr)FNNTNFN)Qr+ __future__rrrrJr2r7loggingr;os.pathrrrrqrmrbase64r email.parserrZpip._vendor.sixrrE pip.compatr pip.downloadrrpip.exceptionsr r r pip.locationsr r rr7rrrrr pip.utils.uirpip.utils.loggingrpip.utils.setuptools_buildrpip._vendor.distlib.scriptsr pip._vendorrpip._vendor.packaging.utilsrZpip._vendor.six.movesr wheel_extrH getLoggerr(robjectrrAr%rlrwrrarbrrrr,r4r=rGrKrMrcr"r"r"r#sn              )'    # 7