a Rak @sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(ddl)m*Z*dd l+m,Z,dd l-m.Z.dd l/m0Z0dd l1m2Z2dd l3m4Z4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;mZ>m?Z?ddl@mAZAmBZBmCZCmDZDddlEmFZFmGZGmHZHmIZIddlJmKZKerddlmLZLGdddeLZMeNeOZPedeQZRe#eReQe$eSeQffZTdPeQeSe#eQeQfdddZUeQeeQefdddZVeQeWdd d!ZXeeWd"d#d$ZYe4e#eeQeQfeeQeQffd%d&d'ZZe!eQe eQd(d)d*Z[eeTee#eQeQeQfd+d,d-Z\eReQd.d/d0Z]dQeQe eQeRd1d2d3Z^eeeQeeReRfe"eReeQeQeeTd4d5d6Z_eeQeQfeeQd7d8d9Z`Gd:d;d;ZaGdd?d?e0ZceQdd@dAdBZdGdCdDdDe*ZedReQe'eQeWddStjt }d|tj d}| }Wdn1s~0Yt|d$}| || |Wdn1s0YdS) zQReplace #!python with #!/path/to/python Return True if file was changed. rbs#!pythonNFs#!asciiwbT) osrEisfileopenreadline startswithsys executableencodegetfilesystemencodinglinesepreadwrite)rEZscript firstlineZexenamerestr9r9r< fix_script]s  &  (rg)metadatar7cCs|dddkS)NzRoot-Is-PurelibrPtrue)getlower)rhr9r9r<wheel_root_is_purelibqsrl)distr7cCsLi}i}|D]2}|jdkr,|j||j<q|jdkr|j||j<q||fS)Nconsole_scripts gui_scripts)Ziter_entry_pointsgroupvaluename)rmrnro entry_pointr9r9r<get_entrypointsus   rt)scriptsr7c s|sdStt}|D]*}tj|}tj|}|||qddtj dd tj D tj tjtjfdd|D}|sdSg}|D]b\}}t|}t|dkrd |d } n$d d |dd d|d } | d| |qd} t|dkr0| | dn| | dtddtj dd tj D} | rxd} | | d|S)zDetermine if any scripts are not on PATH and format a warning. Returns a warning message if one or more scripts are not on PATH, otherwise None. NcSs g|]}tj|tjqSr9)rYrEnormcaserKsep.0ir9r9r< sz5message_about_scripts_not_on_PATH..PATHrPcs&i|]\}}tj|vr||qSr9)rYrErv)ry parent_dirruZ not_warn_dirsr9r< sz5message_about_scripts_not_on_PATH..z script {} isrzscripts {} are, z and z.The {} installed in '{}' which is not on PATH.zeConsider adding {} to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.zthis directoryzthese directoriescss|]}|r|ddkVqdS)r~Nr9rxr9r9r< sz4message_about_scripts_not_on_PATH..ziNOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications. ) collections defaultdictsetrYrEdirnamebasenameaddenvironrjsplitpathsepappendrvr^r_itemssortedlenformatjoinany) ruZgrouped_by_dirdestfiler}Z script_nameZwarn_for msg_linesZ dir_scriptsZsorted_scriptsZ start_textZ last_line_fmtZwarn_for_tildeZtilde_warning_msgr9r~r<!message_about_scripts_not_on_PATHsT      r)outrowsr7cCstdd|DS)aNormalize the given rows of a RECORD file. Items in each row are converted into str. Rows are then sorted to make the value more predictable for tests. Each row is a 3-tuple (path, hash, size) and corresponds to a record of a RECORD file (see PEP 376 and PEP 427 for details). For the rows passed to this function, the size can be an integer as an int or string, or the empty string. css"|]\}}}||t|fVqdSr8)rB)ry record_pathZhash_sizer9r9r<rsz&_normalized_outrows..)r)rr9r9r<_normalized_outrowssrrr7cCs|Sr8r9)rr9r9r<_record_to_fs_pathsr)rE relative_tor7cCsX|dur>tj|dtj|dkr>tj||}|tjjd}td|S)Nr/r2)rYrE splitdriverkrelpathr&rwr)rErr9r9r<_fs_to_record_pathsr) old_csv_rows installedr5 generatedlib_dirr7cCsg}|D]}t|dkr$td|td|d}|||}||vrXtt|\} } n0t|dkrl|dnd} t|dkr|dnd} ||| | fq|D]*} t| |} t| \} } || | | fq| D]} || ddfq|S)z_ :param installed: A map from archive RECORD path to installation RECORD path. z,RECORD line has more than three elements: %sr2rrrP) rloggerwarningrpoprNrrrvalues)rrr5rrZinstalled_rowsrowZold_record_pathZnew_record_pathrIrMfrEZinstalled_record_pathr9r9r<get_csv_rows_for_installeds$       r)consoler7cCs|}g}|dd}|rdtjvr4|d|tjdddkr^|dtjd||dt d |d d |D}|D] }||=q|d d}|rdtjvr|d ||dt |dd |D}|D] }||=q| t dj| |S)zk Given the mapping from entrypoint name to callable, return the relevant console script specs. ZpipNZENSUREPIP_OPTIONSzpip = rPZ altinstallz pip{} = {}rz = cSsg|]}td|r|qS)zpip(\d(\.\d)?)?$rematchrykr9r9r<r{Jz,get_console_script_specs..Z easy_installzeasy_install = zeasy_install-{} = {}cSsg|]}td|r|qS)zeasy_install(-\d\.\d)?$rrr9r9r<r{Xs{} = {}) copyrrYrrrjrr^ version_inforextendrr)rscripts_to_generateZ pip_scriptZpip_eprZeasy_install_scriptZeasy_install_epr9r9r<get_console_script_specss<#    rc@s<eZdZeeeddddZedddZdddd Z dS) ZipBackedFileN)r3r4zip_filer7cCs||_||_||_d|_dSNF)r3r4 _zip_filer5)r;r3r4rr9r9r<__init__eszZipBackedFile.__init__r6cCs|j|jSr8)rZgetinfor3r:r9r9r<_getinfomszZipBackedFile._getinfoc Cstj|j}t|tj|jr0t|j|}|j |H}t |jd}t ||Wdn1st0YWdn1s0Yt |rt |jdS)NrX)rYrErr4r(existsunlinkrrr[shutilZ copyfileobjr.r-)r;r}Zzipinfordestr9r9r<r=ps  HzZipBackedFile.save) r>r?r@r2rBrrrrr=r9r9r9r<rds  rc@s*eZdZdddddZddddZdS) ScriptFiler1Nfiler7cCs$||_|jj|_|jj|_d|_dSr)_filer3r4r5)r;rr9r9r<rs  zScriptFile.__init__r6cCs|jt|j|_dSr8)rr=rgr4r5r:r9r9r<r=s zScriptFile.save)r>r?r@rr=r9r9r9r<rsrcs$eZdZeddfdd ZZS)MissingCallableSuffixN)rsr7cstd|dS)NzInvalid script entry point: {} - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.)superrr)r;rs __class__r9r<rs zMissingCallableSuffix.__init__)r>r?r@rBr __classcell__r9r9rr<rsr) specificationr7cCs*t|}|dur&|jdur&tt|dSr8)rsuffixrrB)rentryr9r9r<_raise_for_invalid_entrypointsrcs4eZdZdeeeefeedfdd ZZS)PipScriptMakerN)roptionsr7cst|t||Sr8)rrmake)r;rrrr9r<rszPipScriptMaker.make)N) r>r?r@rBr r rrrr9r9rr<rsrTF) rr wheel_zip wheel_pathscheme pycompilewarn_script_location direct_url requestedr7c8 st||\}} t| r|jn|jitg} d4tttddfdd } ttddd} ttdd fd d ttt tgd fd fdd } tt t tgd fdfdd }ttddd}t t t| }t| |}t||\}}| |}t||}ttddd}t||\}}|||}t||}t||}ttt|}t|\d tdfdd }t||}t||}tt|}t||}|D] }|| |j|j|jqttdfdd }ttddd} |rt}!txtd|D]V}"t j!|"d d d!}#|#r| |"}$t"j#$|$sHJt d"|$%t"j#j&d#}%| |%|$qWdn1s0YWdn1s0Yt'(|!)t*d|j+}&d |&_,d$h|&_-d |&_.t/}'t0t1d%j23}(|&4|'})| 5|)| 5|&4|(d&d i|rBt6|)}*|*durBt'7|*d't8@t9j:tt;tt<d(fd)d* }+t"j#=|},t"j#=|,d+}-|+|-}.|.>d,Wdn1s0Y| ?|-|dur(t"j#=|,t@}/|+|/$}0|0>|ABd-Wdn1s0Y| ?|/|rrt"j#=|,d.}1tC|1d/Wdn1s^0Y| ?|1|Dd0}2t0tEF|2G}3tH|3| d1}4t"j#=|,d0}5|+|5fitId2.}6tEJt d3|6}7|7KtL|4Wdn1s0YdS)5aInstall a wheel. :param name: Name of the project to install :param wheel_zip: open ZipFile for wheel being installed :param scheme: Distutils scheme dictating the install directories :param req_description: String used in place of the requirement, for logging :param pycompile: Whether to byte-compile installed Python files :param warn_script_location: Whether to check that scripts are installed into a directory on PATH :raises UnsupportedWheel: * when the directory holds an unpacked wheel with incompatible Wheel-Version * when the .dist-info dir does not match the wheel FN)srcfilermodifiedr7cs(t|}||<|r$t|dS)z6Map archive RECORD paths to installation RECORD paths.N)rr)rrrnewpath)r5rrr9r<record_installeds z(_install_wheel..record_installedrUcSs |dS)Nr)endswithrEr9r9r< is_dir_pathsz#_install_wheel..is_dir_path) dest_dir_path target_pathr7cs$t||s d}t|||dS)NzRThe wheel {!r} has a file {!r} trying to install outside the target directory {!r})r,rr)rrmessage)rr9r<assert_no_path_traversals   z0_install_wheel..assert_no_path_traversalr1)rrr7cstddfdd }|S)Nr1rcs0tj|}tj|}|t||Sr8)rYrEnormpathrr)r normed_pathr4)rrrr9r<make_root_scheme_files  zM_install_wheel..root_scheme_file_maker..make_root_scheme_file)r2)rrr)r)rrr<root_scheme_file_makersz._install_wheel..root_scheme_file_maker)rrr7cs0fddtDtddfdd }|S)Ncsi|]}|t|qSr9)getattr)rykey)rr9r<rrzB_install_wheel..data_scheme_file_maker..r1rc stj|}z|tjjd\}}}Wn&tyLd|}t|Yn0z |}Wn8tyd t }d|||}t|Yn0tj ||}||t ||S)NrzbUnexpected file in {}: {!r}. .data directory contents should be named like: '/'.rzUnknown scheme key used in {}: {} (for file {!r}). .data directory contents should be in subdirectories named with a valid scheme key ({})) rYrErrrw ValueErrorrrKeyErrorrrr) rr_Z scheme_keyZ dest_subpathrZ scheme_pathZvalid_scheme_keysr4)r scheme_pathsrrr9r<make_data_scheme_files*     zM_install_wheel..data_scheme_file_maker..make_data_scheme_file)r#r2)rrr)rr)rrrr<data_scheme_file_makersz._install_wheel..data_scheme_file_makercSs|ddddS)Nrrr.data)rrrr9r9r<is_data_scheme_pathsz+_install_wheel..is_data_scheme_pathcSs2|dd}t|dko0|ddo0|ddkS)Nrrrrrru)rrr)rEpartsr9r9r<is_script_scheme_path"s z-_install_wheel..is_script_scheme_pathrcsz|j}tj|}|dr.|dd}n<|drJ|dd}n |drf|dd}n|}|vpx|vS)Nz.exez -script.pyiz.pya)r4rYrErrkr)rrErrZ matchname)rguir9r<is_entrypoint_wrapper5s z-_install_wheel..is_entrypoint_wrapperr6c3sHttD]2}tj|}tj|s0q|ds.pyc_source_file_pathscSs tj|S)z8Return the path the pyc file would have been written to.) importlibutilcache_from_sourcerr9r9r<pyc_output_path]sz'_install_wheel..pyc_output_pathignoreT)forcequietr2rrPrri)rEkwargsr7c;sTt|fi|}|VWdn1s,0Yt|jt|j|dSr8)r%rYchmodrrr&)rErr)generated_file_moder9r<_generate_files$z&_install_wheel.._generate_fileZ INSTALLERspip rQZ REQUESTEDrXZRECORD)rr5rrwzIO[str])F)Mr/rlZpurelibZplatlibrr2rBrCrr r$rrZnamelistrr*maprr rrrtrr=r3r4r5rr'warningscatch_warningsfilterwarnings compileall compile_filerYrErr&rwrdebuggetvaluerruZclobberZvariantsZset_moderlistrrrZ make_multiplerrrr+ contextlibcontextmanagerr r rrdrr!Zto_jsonr`r[ read_textcsvreader splitlinesrrTwriterZ writerowsr)8rrrrrrrrrZinfo_dirrhrrrrrrpathsZ file_pathsZroot_scheme_pathsZdata_scheme_pathsrfilesrZother_scheme_pathsZscript_scheme_pathsrZother_scheme_filesZ distributionrZscript_scheme_filesrrrstdoutrEsuccessZpyc_pathZpyc_record_pathZmakerrZgui_scripts_to_generateZgenerated_console_scriptsmsgrZ dest_info_dirZinstaller_pathZinstaller_fileZdirect_url_pathZdirect_url_fileZrequested_pathZ record_textZ record_rowsZrowsrZ record_filerr9)rr5rrrrrrr<_install_wheels     !              N       *   4      r)req_descriptionr7c csPz dVWn@tyJ}z(d||jd}t||WYd}~n d}~00dS)NzFor req: {}. {}r)rrargs)r err9r9r<req_error_contexts  r#) rrrrr rrrrr7c Cspt|ddP}t|(t||||||||dWdn1sD0YWdn1sb0YdS)NT)Z allowZip64)rrrrrrrrr)rr#r) rrrrr rrrrzr9r9r< install_wheels  r%)rD)N)TTNF)TTNF)j__doc__rrrrrZloggingZos.pathrYrrr^r base64rZ email.messager itertoolsrrrtypingrrr r r r r rrrrrrrrrZzipfilerrZpip._vendor.distlib.scriptsrZpip._vendor.distlib.utilrZpip._vendor.packaging.utilsrZpip._internal.exceptionsrZpip._internal.locationsrZpip._internal.metadatarrr Zpip._internal.models.direct_urlr!r"Zpip._internal.models.schemer#r$Zpip._internal.utils.filesystemr%r&Zpip._internal.utils.miscr'r(r)r*Zpip._internal.utils.unpackingr+r,r-r.Zpip._internal.utils.wheelr/r0r1Z getLoggerr>rrBr2intZInstalledCSVRowrNrTrCrgrlrtrrrrrrrrrrrrrr#r%r9r9r9r<s  H         ( I    Q(