Re@Q@sZdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZmZddlmZmZddlmZdd lmZdd lmZdd lmZmZmZdd lm Z dd l!m"Z"dd lm Z dZ#d0Z$dd1ddZ%ye&ddZ'Wne(k rddZ'YnXddZ)ddZ*ej+dej,Z-ddZ.ddZ/d ddd!ddd"d#Z0d$d%Z1e1d&d'Z2d(d)Z3d*d+Z4Gd,d-d-e5Z6Gd.d/d/e5Z7dS)2zH Support for installing and building the "wheel" binary package format. )with_statementN)urlsafe_b64encode)Parser) ConfigParserStringIO)InvalidWheelFilenameUnsupportedWheel)distutils_scheme)logger) pep425tags)call_subprocessnormalize_pathmake_path_relative) pkg_resources) ScriptMakerz.whlsha256c Cstj|}d}t|dO}|j|}x6|rn|t|7}|j||j|}q9WWdQXdt|jjdj d}||fS)z6Return (hash, length) for path using hashlib.new(algo)rrbNzsha256=latin1=) hashlibnewopenreadlenupdaterdigestdecoderstrip)pathalgo blocksizehlengthfblockrr'$/tmp/pip-ztkk0jow-build/pip/wheel.pyrehash"s  (r)cCs t|tr|jdS|S)Nascii) isinstanceunicodeencode)sr'r'r(binary1s r/cCs t|tr|jdSdS)Nr*)r+strr-)r.r'r'r(r/6scCsItjddkr"i}d}nidd6}d}t||||S)Nrbnewline)sys version_infor)namemodenlbinr'r'r( open_for_csv:s   r;cCstjj|rt|d}zj|j}|jtdsIdStjj tj }td|ttj }|j }Wd|j Xt|d}z|j||j|Wd|j XdSdS)zLReplace #!python with #!/path/to/python Return True if file was changed.rz#!pythonFz#!NwbT)osr isfilerreadline startswithr/r5 executabler-getfilesystemencodinglineseprclosewrite)r script firstlineexenamerestr'r'r( fix_scriptCs     rJzZ^(?P(?P.+?)(-(?P\d.+?))?) \.dist-info$c Cs|jdd}xtj|D]}tj|}|r"|jd|kr"ttjj||d:}x0|D](}|j j }|dkrzdSqzWWdQXq"q"WdS) zP Return True if the extracted wheel in wheeldir should go into purelib. -_r7WHEELzroot-is-purelib: trueTNF) replacer=listdir dist_info_rematchgrouprr joinlowerr)r7wheeldir name_foldeditemrQwheelliner'r'r(root_is_purelib]s!  rZc Cstjj|siifSt|N}t}x.|D]&}|j|j|jdq;W|jdWdQXtj }|j |i}i}|j drt |j d}n|j drt |j d}n||fS)N rconsole_scripts gui_scripts)r=r existsrrrEstripseekrRawConfigParserreadfp has_sectiondictitems)filenamefpdatarYcpconsoleguir'r'r(get_entrypointsms"     rlFTc $s(|s't|d|d|d|}nt| rC|dn |dgg jtjjtjj} itg} |rtj| ddddnd d d  fd d  dd fdd} | | ds#t d tjj dd} t | \fdd} xD]}d}d}xtj tjj |D]e}d}|dkrt }| }ntjj ||} ||}| | |d d|d|qWqjWtd|dtd2_d_fdd}|_d_jdd}|rSdtjkrd|}| jj|ntjjddd krd!tjdd"|f}| jj|nd!tjdd#|f}| jj|d$d%D}x|D] }|=q?Wnjd&d}|rdtjkrd'|}| jj|nd(tjdd#|f}| jj|d)d%D}x|D] }|=qWntdkr<| jjd*d%jDntdkr| jjd+d%jDidd,6ntjj dd-}tjj dd.}t|d/M}t|d05}tj|}tj |}xj|D]b} j| d| d| d<| dkrTt!| d\| d"<| d1.normpathFcsB|}|}||<|r>j|ndS)z6Map archive RECORD paths to installation RECORD paths.N)add)srcfiledestfilemodifiedoldpathnewpath)changed installedlib_dirrxrUr'r(record_installeds  z*move_wheel_files..record_installedNcs&tjj|s"tj|nxtj|D]\}}}|t|djtjj}tjj||} |r|j tjjddj drq2nx|D]} tjj||| } |r|dkr| j drj | qq|r| j dr| j j jjddj r sWtdj | qqWx|D]} |r|| rqrntjj|| } tjj||| }tjj| stj| ntj| |d }|r ||}n| ||qrWq2WdS) Nrrz.datar3z .dist-inforKrLzMultiple .dist-info directoriesF)r=r r^makedirswalkrlstriprurSsplitendswithappendrTr@ project_namerNAssertionErrorshutilcopy2)sourcedestis_basefixerfilterdirsubdirsfilesbasedirdestdirr. destsubdirr%rzr{r) data_dirsinfo_dirrreqr'r(clobbers:%+ ! * z!move_wheel_files..clobberz!%s .dist-info directory not foundrzentry_points.txtcs|jjdr(|dd}nV|jjdrP|dd}n.|jjdrx|dd}n|}|kp|kS) Nz.exez -script.py z.pyair)rTr)r7 matchname)rjrkr'r(is_entrypoint_wrappersz/move_wheel_files..is_entrypoint_wrapperscriptsrrr3cs6ji|jd6|jjddd6|jd6S)Nmodule.r import_namefunc)script_templateprefixsuffixr)entry)makerr'r(_get_script_text s  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()) pipENSUREPIP_OPTIONSzpip = altinstallz pip%s = %srr1cSs(g|]}tjd|r|qS)zpip(\d(\.\d)?)?$)rerQ).0kr'r'r( Js z$move_wheel_files.. easy_installzeasy_install = zeasy_install-%s = %scSs(g|]}tjd|r|qS)zeasy_install(-\d\.\d)?$)rrQ)rrr'r'r(rVs cSsg|]}d|qS)z%s = %sr')rkvr'r'r(r]s cSsg|]}d|qS)z%s = %sr')rrr'r'r(r_s rkRECORDz RECORD.piprzw+)r3)'r rZrr=r ruset compileall compile_dirrrSrlrOrJrvariantsset_moderrpopenvironextendmakegetr5versionr make_multiplerer;csvreaderwriterr)writerowr@relpathrmove)$r7rrUrmrnro pycompileschemestrip_file_prefixr generatedrep_filerdatadirrrsubdirrr pip_scriptspecpip_epreasy_install_scripteasy_install_eprecord temp_record record_in record_outrrrowr%r#lr') rrjrrkrrrrrxrrrUr(move_wheel_filess!    !!( %   $  #    ,6 ! * *rcs%tjfdd}|S)Nc?sHt}x8||D]'}||kr|j||VqqWdS)N)rry)argskwseenrW)fnr'r(uniquevs    z_unique..unique) functoolswraps)rrr')rr(_uniqueus!rccsddlm}tj||jd}x|D]}tjj|j|d}|V|j dr5tjj |\}}|dd}tjj||d}|Vq5q5WdS) 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.pyNr1z.pyc) pip.reqrrrget_metadata_linesr=r rSlocationrr)distrrrr dnrbaser'r'r(uninstallation_pathss  rc Csyzddtjd|Dd}|jd}tj|}|dj}ttt|j d}|SWn dSYnXdS) 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(rs z!wheel_version..NrrMz Wheel-VersionrF) r find_on_path get_metadatarparsestrr_tuplemapintr) source_dirr wheel_datarr'r'r( wheel_versions#rcCs|std|n|dtdkrXtd|djtt|fn2|tkrtjddjtt|ndS)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)rVERSION_COMPATIBLErSrr0r warn)rr7r'r'r(check_compatibilitys %  rc@sUeZdZdZejdejZddZdddZ ddd Z dS) Wheelz A wheel filez^(?P(?P.+?)-(?P\d.*?)) ((-(?P\d.*?))?-(?P.+?)-(?P.+?)-(?P.+?) \.whl|\.dist-info)$csjj|}|s+td|n|_|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.r7rLrKverpyverrabiplatc3s>|]4}jD]$}jD]}|||fVqqqdS)N)abisplats)rxyz)selfr'r( sz!Wheel.__init__..N) wheel_file_rerQrrfrRrNr7rr pyversionsrrr file_tags)rrf wheel_infor')rr(__init__s zWheel.__init__NcsHdkrtjnfdd|jD}|rDt|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. Ncs+g|]!}|krj|qSr')index)rc)tagsr'r(rs z+Wheel.support_index_min..)r supported_tagsr min)rrindexesr')rr(support_index_mins  zWheel.support_index_mincCs4|dkrtj}ntt|j|jS)z'Is this wheel supported on this system?N)r rboolr intersectionr )rrr'r'r( supporteds  zWheel.supported) __name__ __module__ __qualname____doc__rcompileVERBOSErr rrr'r'r'r(rs    rc@s@eZdZdZggddZddZddZdS) WheelBuilderz#Build wheels from a RequirementSet.cCs7||_||_t||_||_||_dS)N)requirement_setfinderr wheel_dir build_optionsglobal_options)rrrrr r!r'r'r(r s    zWheelBuilder.__init__c Cstjdd|jgt|j}tjd|jtjd|j|dd|jg|j }y!t |d|j dd d SWn tj d |jd SYnXd S) zBuild one wheel.z-czjimport setuptools;__file__=%r;exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))z#Running setup.py bdist_wheel for %szDestination directory: %s bdist_wheelz-dcwd show_stdoutFTzFailed building wheel for %sN) r5rAsetup_pylistr!r notifyr7rr r rerror)rr base_args wheel_argsr'r'r( _build_ones  zWheelBuilder._build_onecCs5|jj|j|jjj}dd|D}|sBdStjddjdd|Dtjd7_gg}}x:|D]2}|j |r|j |q|j |qWtjd8_|rtjdd jd d|Dn|r1tjd d jd d|DndS) z Build wheels.cSsg|]}|js|qSr')is_wheel)rrr'r'r(rs z&WheelBuilder.build..Nz*Building wheels for collected packages: %s,cSsg|]}|jqSr')r7)rrr'r'r(r#s rzSuccessfully built %s cSsg|]}|jqSr')r7)rrr'r'r(r0s zFailed to build %scSsg|]}|jqSr')r7)rrr'r'r(r2s ) r prepare_filesr requirementsvaluesr r'rSindentr+r)rreqsetbuildset build_success build_failurerr'r'r(builds&  *zWheelBuilder.buildN)rrrrr r+r7r'r'r'r(rs  r)rri)8r __future__rrrrrr=rrr5base64r email.parserrZpip.backwardcompatrrpip.exceptionsrr pip.locationsr pip.logr rr pip.utilr r r pip._vendorrpip._vendor.distlib.scriptsr wheel_extrr)r,r/ NameErrorr;rJrrrPrZrlrrrrrobjectrrr'r'r'r(sT                 2