o 7]hk@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$eSeQffZTd[deQdeSde#eQeQffddZUdeQdeeQeffdd ZVdeQdeWfd!d"ZXd#edeWfd$d%ZYd&e4de#eeQeQfeeQeQfffd'd(ZZd)e!eQde eQfd*d+Z[d,eeTdee#eQeQeQffd-d.Z\d/eRdeQfd0d1Z]d\deQd2e eQdeRfd3d4Z^d5eeeQd6eeReRfd7e"eRd8eeQd9eQdeeTf d:d;Z_dZ`Gd?d@d@ZaGdAdBdBZbGdCdDdDe0ZcdEeQddfdFdGZdGdHdIdIe*Ze J J  Kd]dLeQdMe'dNeQdOesz5message_about_scripts_not_on_PATH..PATHrQcs&i|]\}}tj|vr||qSr8)rYrFry)r| parent_dirrx not_warn_dirsr8r; s z5message_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~Nr8r{r8r8r; s   z4message_about_scripts_not_on_PATH..ziNOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications. ) collections defaultdictsetrYrFdirnamebasenameaddenvironrlsplitpathsepappendryr^r_itemssortedlenformatjoinany) rxgrouped_by_dirdestfiler script_namewarn_for msg_lines dir_scriptssorted_scripts start_text last_line_fmtwarn_for_tildetilde_warning_msgr8rr;!message_about_scripts_not_on_PATHsT        routrowscCstdd|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|fVqdSr7)rC)r| record_pathhash_sizer8r8r;rs z&_normalized_outrows..)r)rr8r8r;_normalized_outrowssrrcCs|Sr7r8)rr8r8r;_record_to_fs_pathr=r relative_tocCsX|durtj|dtj|dkrtj||}|tjjd}td|S)Nr/r2)rYrF splitdrivermrelpathr&rzr)rFrr8r8r;_fs_to_record_paths r old_csv_rows installedr5 generatedlib_dircCsg}|D]H}t|dkrtd|td|d}|||}||vr,tt|\} } nt|dkr6|dnd} t|dkrB|dnd} ||| | fq|D]} t| |} t| \} } || | | fqO| D] } || ddfqi|S)z_ :param installed: A map from archive RECORD path to installation RECORD path. z,RECORD line has more than three elements: %sr2rrrQ) rloggerwarningrpoprOrrrvalues)rrr5rrinstalled_rowsrowold_record_pathnew_record_pathrJrNfrFinstalled_record_pathr8r8r;get_csv_rows_for_installeds$       rconsolecCs|}g}|dd}|rJdtjvr|d|tjdddkr/|dtjd||dt d |d d |D}|D]}||=qD|d d}|rwdtjvr^|d ||dt |dd |D}|D]}||=qq| t dj| |S)zk Given the mapping from entrypoint name to callable, return the relevant console script specs. pipNENSUREPIP_OPTIONSzpip = rQ altinstallz pip{} = {}rz = cSg|] }td|r|qS)zpip(\d(\.\d)?)?$rematchr|kr8r8r;r~Jsz,get_console_script_specs.. easy_installzeasy_install = zeasy_install-{} = {}cSr)zeasy_install(-\d\.\d)?$rrr8r8r;r~Xs  {} = {}) copyrrYrrrlrr^ version_inforextendrr)rscripts_to_generate pip_scriptpip_epreasy_install_scripteasy_install_epr8r8r;get_console_script_specss< #   rc@s>eZdZdedededdfddZdefdd Zd d d Z dS) ZipBackedFiler3r4zip_filer6NcCs||_||_||_d|_dSNF)r3r4 _zip_filer5)r:r3r4rr8r8r;__init__es zZipBackedFile.__init__cCs|j|jSr7)rgetinfor3r9r8r8r;_getinfomszZipBackedFile._getinfoc Cstj|j}t|tj|jrt|j|}|j |$}t |jd}t ||Wdn1s:wYWdn1sIwYt |rYt |jdSdS)NrX)rYrFrr4r(existsunlinkrrr[shutil copyfileobjr.r-)r:rzipinfordestr8r8r;r<ps zZipBackedFile.saver>) r?r@rAr2rCrrrrr<r8r8r8r;rds rc@s eZdZd ddZd ddZdS) ScriptFilefiler1r6NcCs$||_|jj|_|jj|_d|_dSr)_filer3r4r5)r:rr8r8r;rs   zScriptFile.__init__cCs|jt|j|_dSr7)rr<rir4r5r9r8r8r;r<s zScriptFile.save)rr1r6Nr>)r?r@rArr<r8r8r8r;rs rcs&eZdZdeddffdd ZZS)MissingCallableSuffixrvr6Ncstd|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:rv __class__r8r;rszMissingCallableSuffix.__init__)r?r@rArCr __classcell__r8r8rr;rsr specificationcCs.t|}|dur|jdurtt|dSdSr7)rsuffixrrC)rentryr8r8r;_raise_for_invalid_entrypoints rcs8eZdZddedeeefdeeffdd ZZS)PipScriptMakerNroptionsr6cst|t||Sr7)rrmake)r:rrrr8r;rszPipScriptMaker.maker7) r?r@rArCr r rrrr8r8rr;rs0rTFru wheel_zip wheel_pathscheme pycompilewarn_script_location direct_url requestedc8 s(t||\}} t| r|jn|jitg} d8dtdtdtddffdd } d tdtfd d } d td tddffdd dtdtdt tgdfffdd } dtdt dt tgdfffdd }d tdtfdd}t t t| }t| |}t||\}}| |}t||}d tdtfdd}t||\}}|||}t||}t||}ttt|}t|\dddtffdd }t||}t||}tt|}t||}|D]}|| |j|j|jqdttffdd }d tdtfd!d"} |rktQ}!t<td#|D]+}"t j!|"d$d$d%}#|#rB| |"}$t"j#$|$s2Jt d&|$%t"j#j&d'}%| |%|$qWdn 1sOwYWdn 1s_wYt'(|!)t*d|j+}&d$|&_,d(h|&_-d$|&_.t/}'t0t1d)j23}(|&4|'})| 5|)| 5|&4|(d*d$i|rt6|)}*|*durt'7|*d+t8@t9j:d td,t;dtt<ffd-d. }+t"j#=|},t"j#=|,d/}-|+|- }.|.>d0Wdn 1swY| ?|-|dur$t"j#=|,t@}/|+|/}0|0>|ABd1Wdn 1swY| ?|/|rIt"j#=|,d2}1tC|1d3Wdn 1s?wY| ?|1|Dd4}2t0tEF|2G}3tH|3| d5}4t"j#=|,d4}5|+|5fitId6}6tEJt d7|6}7|7KtL|4WddS1swYdS)9aInstall 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 Fsrcfilermodifiedr6Ncs,t|}||<|rt|dSdS)z6Map archive RECORD paths to installation RECORD paths.N)rr)rrrnewpath)r5rrr8r;record_installeds z(_install_wheel..record_installedrFcSs |dS)Nr)endswithrFr8r8r; is_dir_paths z#_install_wheel..is_dir_path dest_dir_path target_pathcs$t||sd}t|||dS)NzRThe wheel {!r} has a file {!r} trying to install outside the target directory {!r})r,rr)rrmessage)rr8r;assert_no_path_traversals  z0_install_wheel..assert_no_path_traversalrrr1csdtddffdd }|S)Nrr6r1cs0tj|}tj|}|t||Sr7)rYrFnormpathrr)r normed_pathr4)rrrr8r;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_makerrcs2fddtDdtddffdd }|S)Ncsi|]}|t|qSr8)getattr)r|key)rr8r;rszB_install_wheel..data_scheme_file_maker..rr6r1c stj|}z |tjjd\}}}Wnty$d|}t|wz|}WntyEd t }d|||}t|wtj ||}||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 ({})) rYrFrrrz ValueErrorrrKeyErrorrrr) rr_ scheme_key dest_subpathr scheme_pathvalid_scheme_keysr4)r scheme_pathsrrr8r;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)rrrr8r8r;is_data_scheme_pathsz+_install_wheel..is_data_scheme_pathcSs2|dd}t|dko|ddo|ddkS)Nrrrrrrx)rrr)rFpartsr8r8r;is_script_scheme_path"s &z-_install_wheel..is_script_scheme_pathrcsz|j}tj|}|dr|dd}n|dr%|dd}n|dr3|dd}n|}|vp<|vS)Nz.exez -script.pyiz.pya)r4rYrFrrmr)rrFru matchname)rguir8r;is_entrypoint_wrapper5s z-_install_wheel..is_entrypoint_wrapperc3sJttD]}tj|}tj|sq |dsq |Vq dS)Nz.py)rrrrYrFrrZr)installed_pathfull_installed_path)rrr8r;pyc_source_file_pathsPs  z-_install_wheel..pyc_source_file_pathscSs tj|S)z8Return the path the pyc file would have been written to.) importlibutilcache_from_sourcerr8r8r;pyc_output_path]s z'_install_wheel..pyc_output_pathignoreT)forcequietr2rrQrrikwargsc;sVt|fi| }|VWdn1swYt|jt|j|dSr7)r%rYchmodrur&)rFr'r)generated_file_moder8r;_generate_files z&_install_wheel.._generate_file INSTALLERspip rR REQUESTEDrXRECORD)rr5rrwzIO[str])F)Mr/rnpurelibplatlibrr2rCrDrr r$rrnamelistrr*maprr rrrwrr<r3r4r5rr'warningscatch_warningsfilterwarnings compileall compile_filerYrFrr&rzrdebuggetvaluerrxclobbervariantsset_moderlistrrr make_multiplerrrr+ contextlibcontextmanagerr r rrdrr!to_jsonr`r[ read_textcsvreader splitlinesrrUwriter writerowsr)8rurrrrrrrinfo_dirrjrrrrrrpaths file_pathsroot_scheme_pathsdata_scheme_pathsrfilesrother_scheme_pathsscript_scheme_pathsrother_scheme_files distributionrscript_scheme_filesrrr#stdoutrFsuccesspyc_pathpyc_record_pathmakerrgui_scripts_to_generategenerated_console_scriptsmsgr* dest_info_dirinstaller_pathinstaller_filedirect_url_pathdirect_url_filerequested_path record_text record_rowsrowsr record_filerFr8)rr5rr)rrrrr;_install_wheels     !                                $rereq_descriptionc csDzdVWdSty!}zd||jd}t||d}~ww)NzFor req: {}. {}r)rrargs)rferr8r8r;req_error_contexts  ric Cst|dd1}t|t||||||||dWdn1s"wYWddSWddS1s:wYdS)NT) allowZip64)rurrrrrrr)rrire) rurrrfrrrrzr8r8r; install_wheels  "rl)rEr7)TTNF)j__doc__rr6r?rCr loggingos.pathrYrrr^r3base64r email.messager itertoolsrrrtypingrrr r r r r rrrrrrrrrzipfilerrpip._vendor.distlib.scriptsrpip._vendor.distlib.utilrpip._vendor.packaging.utilsrpip._internal.exceptionsrpip._internal.locationsrpip._internal.metadatarrr pip._internal.models.direct_urlr!r"pip._internal.models.schemer#r$pip._internal.utils.filesystemr%r&pip._internal.utils.miscr'r(r)r*pip._internal.utils.unpackingr+r,r-r.pip._internal.utils.wheelr/r0r1 getLoggerr?rrCr2intInstalledCSVRowrOrUrDrirnrwrrrrrrrrrrrrer@rirlr8r8r8r;s  H         * H     Q(