U .eH@s4dZddlmZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lm Z m!Z!m"Z"dd l#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>ddl?m@Z@e:rddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddlVmWZWeGeXdfZYeLeQgeZfZ[d Z\e]e^Z_d!d"Z`dXd$d%ZadYd&d'Zbd(d)Zcd*d+Zdd,d-Zee fd.e jgZhd/d0Zid1d2Zjd3d4Zkd5d6Zld7d8ZmGd9d:d:enZod;d<ZpGd=d>d>eZqdZdAdBZrdCdDZsdEdFZtdGdHZuGdIdJdJevZwe fdKe jxfdLdMZydNdOZzdPdQZ{dRdSZ|dTdUZ}GdVdWdWevZ~dS)[zH Support for installing and building the "wheel" binary package format. )absolute_importN)urlsafe_b64encode)Parser) pkg_resources) ScriptMaker)get_export_entry)canonicalize_name)StringIO) pep425tags)InstallationErrorInvalidWheelFilenameUnsupportedWheel)distutils_schemeget_major_minor_version)Link) indent_log)has_delete_marker_file)captured_stdout ensure_dir read_chunks)make_setuptools_shim_args) LOG_DIVIDERcall_subprocessformat_command_argsrunner_with_spinner_message) TempDirectory)MYPY_CHECK_RUNNING) open_spinner) unpack_file) path_to_url) DictListOptionalSequenceMappingTupleIOTextAnyIterableCallableSet) Requirement)InstallRequirement)RequirementPreparer) WheelCache) Pep425Tag.)rcCstj||tjjdS)N/)ospathrelpathreplacesep)srcpr:7/usr/lib/python3.8/site-packages/pip/_internal/wheel.pynormpathOsr<c CsRt}d}t|d.}t||dD]}|t|7}||q$W5QRX||fS)z5Return (hash, length) for path using hashlib.sha256()rrb)size)hashlibZsha256openrlenupdate)r4 blocksizehlengthfblockr:r:r; hash_fileSs  rIcCs6t||\}}dt|dd}|t|fS)z?Return (encoded_digest, length) for path using hashlib.sha256()zsha256=latin1=)rIrdigestdecoderstripstr)r4rDrErFrLr:r:r;rehash_srPcCs6tjddkri}d}n ddi}d}t|||f|S)Nrbnewline)sys version_inforA)namemodenlbinr:r:r; open_for_csvjs r[cCs|d}||d<d|S)zBReplace the Python tag in a wheel file name with a new value. -)splitjoin)Z wheelnameZnew_tagpartsr:r:r;replace_python_tagus rac Cstj|rt|dR}|}|ds8W5QRdStjt }d|tj d}| }W5QRXt|d}| || |W5QRXdSdS) zLReplace #!python with #!/path/to/python Return True if file was changed.r>s#!pythonFs#!asciiwbTN) r3r4isfilerAreadline startswithrU executableencodegetfilesystemencodinglinesepreadwrite)r4Zscript firstlineZexenamerestr:r:r; fix_script~s     rozX^(?P(?P.+?)(-(?P.+?))?) \.dist-info$c Cs|dd}t|D]p}t|}|r|d|krttj||d6}|D]*}| }|dkrPW5QRdSqPW5QRXqdS)zP Return True if the extracted wheel in wheeldir should go into purelib. r\_rWWHEELzroot-is-purelib: trueTF) r6r3listdir dist_info_rematchgrouprAr4r_lowerrN)rWwheeldirZ name_foldeditemrtwheelliner:r:r;root_is_purelibs    r{c stj|siifSt|8}t}|D]}|||dq(|dW5QRXtj |}| di}| di}ddt fdd| D}t fd d| D}||fS) N rZconsole_scriptsZ gui_scriptscSst|dddS)zRget the string representation of EntryPoint, remove space and split on '=' rTrK)rOr6r^)sr:r:r; _split_epsz"get_entrypoints.._split_epc3s|]}|VqdSNr:.0vrr:r; sz"get_entrypoints..c3s|]}|VqdSrr:rrr:r;rs)r3r4existsrAr rlstripseekrZ EntryPointZ parse_mapgetdictvalues)filenamefpdatarzZ entry_pointsconsoleguir:rr;get_entrypointss      rc sJ|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| | dd|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|tjqSr:)r3r4normcaserNr7)rir:r:r; sz5message_about_scripts_not_on_PATH..PATHrTcs&i|]\}}tj|kr||qSr:)r3r4r)r parent_dirscriptsZ not_warn_dirsr:r; sz5message_about_scripts_not_on_PATH..r1z 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 directoriesr|) collections defaultdictsetr3r4dirnamebasenameaddenvironrr^pathsepappendrrUrgitemssortedrBformatr_) rZgrouped_by_dirdestfilerZ script_nameZwarn_for msg_linesZ dir_scriptsZsorted_scriptsZ start_textZ last_line_fmtr:rr;!message_about_scripts_not_on_PATHsH     rcCst|dddS)a; Return the given rows of a RECORD file in sorted order. 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. cSstdd|DS)Ncss|]}t|VqdSr)rO)rxr:r:r;rsz3sorted_outrows....)tuple)rowr:r:r;z sorted_outrows..)key)r)outrowsr:r:r;sorted_outrowssrc Csg}|D]v}t|dkr(td|t|}|d}|||}||d<||krpt|\} } | |d<| |d<|t|q|D]*} t| \} } |t | || t | fq|D]} ||| ddfq|S)z_ :param installed: A map from archive RECORD path to installation RECORD path. rQz,RECORD line has more than three elements: {}rr1rT) rBloggerwarningrlistpoprPrrr<rO) Z old_csv_rows installedchanged generatedlib_dirZinstalled_rowsrZold_pathnew_pathrLrFrGr:r:r;get_csv_rows_for_installeds*     rc@s eZdZdS)MissingCallableSuffixN)__name__ __module__ __qualname__r:r:r:r;r=srcCs*t|}|dk r&|jdkr&tt|dSr)rsuffixrrO) specificationentryr:r:r;_raise_for_invalid_entrypointAsrcseZdZdfdd ZZS)PipScriptMakerNcst|tt|||Sr)rsuperrmake)selfrZoptions __class__r:r;rHszPipScriptMaker.make)N)rrrr __classcell__r:r:rr;rGsrFTc - s\|st|||||| d}t| r,|dn|dgg tjjtjj} itg} |rt4} t t dt j | dddW5QRXW5QRXt | d. fdd d/fd d }|| dstd tjdd}t|\fdd}D]j}d }d }ttj |D]F}d }|dkr`t}|}tj ||} ||}|| |d||dqFq&td |d}d|_dh|_d|_g}dd }|rDdtjkr|d|tjdddkr|dtjd|f|dt|fddD}|D] }|=q6dd }|rdtjkrp|d||dt|fddD}|D] }|=q| d d!!Dd"d!D}g}z.|"|}| || |"|d#diWn>t#k r>}z|j$d} t%d$&| W5d }~XYnX| rbt'|}!|!d k rbt (|!tjdd%}"tjdd&}#t)|#d'}$|$*d(W5QRXt+,|#|"| |"tjdd)}%tjdd*}&t-|%d+\}'t-|&d,F}(t./|'})t0|)| d-}*t.1|(}+t2|*D]},|+3|,q&W5QRXW5QRXt+,|&|%d S)0zInstall a wheel)userhomerootisolatedprefixZpurelibZplatlibignoreT)forcequietFcs.t|}t|}||<|r*|dS)z6Map archive RECORD paths to installation RECORD paths.N)r<r)srcfilerZmodifiedZoldpathnewpath)rrrrwr:r;record_installeds   z*move_wheel_files..record_installedNcst|t|D]\}}}|t|dtjj}tj||} |rf|tjjdd drfq|D]} tj||| } |r|dkr| dr | qjqj|rj| drjt |  t j rjrtd| dd | qj|D]} |r|| rqtj|| } tj||| }t| tj|rFt|t| |t| }ttdr|t||j|jft| tjrt| }|jtjBtjBtjB}t||d }|r||}| ||qqdS) Nr1rz.datarTz .dist-infoz!Multiple .dist-info directories: rutimeF)rr3walkrBlstripr4r7r_r^endswithrrrfrWAssertionErrorrunlinkshutilZcopyfilestathasattrrst_atimest_mtimeaccessX_OKst_modeS_IXUSRS_IXGRPS_IXOTHchmod)sourcedestZis_basefixerfilterdirZsubdirsfilesZbasedirZdestdirr~Z destsubdirrGrrstZ permissionsr) data_dirsinfo_dirrreqr:r;clobbers^         z!move_wheel_files..clobberz!%s .dist-info directory not foundrzentry_points.txtcsh|dr|dd}n<|dr8|dd}n |drT|dd}n|}|kpf|kS)Nz.exez -script.pyiz.pya)rvr)rWZ matchname)rrr:r;is_entrypoint_wrappersz/move_wheel_files..is_entrypoint_wrapperr)rrrTZpipZENSUREPIP_OPTIONSzpip = Z altinstallz pip%s = %scSsg|]}td|r|qS)zpip(\d(\.\d)?)?$rertrkr:r:r;r0s z$move_wheel_files..Z easy_installzeasy_install = zeasy_install-%s = %scSsg|]}td|r|qS)zeasy_install(-\d\.\d)?$rrr:r:r;r@s css|]}d|VqdS)%s = %sNr:rZkvr:r:r;rGsz#move_wheel_files..cSsg|] }d|qS)rr:rr:r:r;rKsrzInvalid script entry point: {} for req: {} - A callable suffix is required. Cf https://packaging.python.org/en/latest/distributing.html#console-scripts for more information.Z INSTALLERz INSTALLER.piprcspip ZRECORDz RECORD.piprzw+)rrrr)F)NN)4rr{rNr3r4r7rrwarningscatch_warningsfilterwarnings compileall compile_dirrdebuggetvaluerr_rrrrorrZvariantsZset_moderrrrrUrVrextendrZ make_multiplerargsr rrrrArlrmover[csvreaderrwriterrZwriterow)-rWrrwrrrZ pycompileZschemerrZwarn_script_locationrrstdoutrZep_filerZdatadirrrZsubdirrZmakerZscripts_to_generateZ pip_scriptZpip_eprZeasy_install_scriptZeasy_install_epZgui_scripts_to_generateZgenerated_console_scriptsermsgZ installerZtemp_installerZinstaller_filerecordZ temp_recordZ record_inZ record_outr rr rr:) rrrrrrrrrrwr;move_wheel_filesMs    $F   #                     "rcCsrzVddtd|Dd}|d}t|}|d}ttt| d}|WSt k rlYdSXdS)z Return the Wheel-Version of an extracted wheel, if possible. Otherwise, return None if we couldn't parse / extract it. cSsg|]}|qSr:r:)rdr:r:r;rsz!wheel_version..Nrrqz Wheel-Version.) rZ find_on_pathZ get_metadatarZparsestrrrmapintr^ Exception) source_dirZdistZ wheel_dataversionr:r:r; wheel_versions   rcCsb|std||dtdkr>td|dtt|fn |tkr^tddtt|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_COMPATIBLEr_rrOrr)rrWr:r:r;check_compatibilitysrcCs d|S)z Format three tags in the form "--". :param file_tag: A 3-tuple of tags (python_tag, abi_tag, platform_tag). r\)r_)Zfile_tagr:r:r; format_tagsrc@s>eZdZdZedejZddZddZ ddZ d d Z d S) Wheelz A wheel filez^(?P(?P.+?)-(?P.*?)) ((-(?P\d[^-]*?))?-(?P.+?)-(?P.+?)-(?P.+?) \.whl|\.dist-info)$csj|}|std||_|ddd_|ddd_|d_|d d_ |d  d_ |d  d_ 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.rWrpr\ZverbuildZpyverrZabiZplatcs.h|]&}jD]}jD]}|||fqqqSr:)abisplats)rryzrr:r; s z!Wheel.__init__..N) wheel_file_rertr rrur6rWrZ build_tagr^Z pyversionsrr file_tags)rrZ wheel_infor:r!r;__init__s   zWheel.__init__cCstdd|jDS)zF Return the wheel's tags as a sorted list of strings. css|]}t|VqdSr)rrtagr:r:r;rsz0Wheel.get_formatted_file_tags..)rr$r!r:r:r;get_formatted_file_tagsszWheel.get_formatted_file_tagscstfdd|jDS)a Return the lowest index that one of the wheel's file_tag combinations achieves in the given list of supported tags. For example, if there are 8 supported tags and one of the file tags is first in the list, then return 0. :param tags: the PEP 425 tags to check the wheel against, in order with most preferred first. :raises ValueError: If none of the wheel's file tags match one of the supported tags. c3s |]}|kr|VqdSr)indexr&tagsr:r;rsz*Wheel.support_index_min..)minr$rr+r:r*r;support_index_minszWheel.support_index_mincCs|j| S)z Return whether the wheel is compatible with one of the given tags. :param tags: the PEP 425 tags to check the wheel against. )r$ isdisjointr-r:r:r; supportedszWheel.supportedN) rrr__doc__rcompileVERBOSEr#r%r(r.r0r:r:r:r;rsrz([a-z0-9_.]+)-([a-z0-9_.!+-]+)cCst||S)zjDetermine whether the string looks like an egg_info. :param s: The string to parse. E.g. foo-2.1 )boolsearch)r~Z _egg_info_rer:r:r;_contains_egg_infosr6cCs|jr dS|jr&|s"td|jdS|s.dS|js:|js>dS||sXtd|jdS|jrj|jjrjdS|j}| \}}|rt |rdSdS)a[ Return whether to build an InstallRequirement object using the ephemeral cache. :param cache_available: whether a cache directory is available for the should_unpack=True case. :return: True or False to build the requirement with ephem_cache=True or False, respectively; or None not to build the requirement. Nz(Skipping %s, due to already being wheel.FzCSkipping wheel build for %s, due to binaries being disabled for it.T) Z constraintis_wheelrinforWZeditablerlinkZis_vcssplitextr6)r should_unpackcache_availablecheck_binary_allowedr9baseZextr:r:r;should_use_ephemeral_cache s4   r?cCs^t|}d|}|s |d7}n:ttjkr8|d7}n"|dsJ|d7}|d|t7}|S)z1 Format command information for logging. zCommand arguments: {} zCommand output: Nonez'Command output: [use --verbose to show]r|zCommand output: {}{})rrrZgetEffectiveLevelloggingDEBUGrr) command_argscommand_outputZ command_desctextr:r:r;format_command_resultGs    rEcCsxt|}|s4d|j}|t||7}t|dSt|dkrfd|j|}|t||7}t|tj ||dS)zH Return the path to the wheel in the temporary build directory. z1Legacy build of wheel for {!r} created no files. Nr1zZLegacy build of wheel for {!r} created more than one file. Filenames (choosing first): {} r) rrrWrErrrBr3r4r_)namestemp_dirrrBrCr r:r:r;get_legacy_build_wheel_path^s$    rHcCsdS)NTr:)rpr:r:r; _always_true~srIc@s\eZdZdZdddZdddZddd Zd d Zdd d ZdddZ ddZ dddZ dS) WheelBuilderz#Build wheels from a RequirementSet.NFcCsD|dkr t}||_||_|j|_|p&g|_|p0g|_||_||_dSr) rIpreparer wheel_cacheZwheel_download_dir _wheel_dir build_optionsglobal_optionsr=no_clean)rrKrLrNrOr=rPr:r:r;r%s   zWheelBuilder.__init__c Cs.|j|j|||dW5QRSQRXdS)ziBuild one wheel. :return: The filename of the built wheel, or None if the build failed.  python_tagN)Z build_env_build_one_inside_env)rr output_dirrRr:r:r; _build_oneszWheelBuilder._build_onec Cstdd}|jr|j}n|j}|||j|d}|dk rtj|}tj||}zNt|\} } t ||t d|j || | t d||WW5QRStk rYnX||W5QRdSQRXdS)Nry)ZkindrQz3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %s)rZ use_pep517_build_one_pep517_build_one_legacyr4r3rr_rIrrrr8rWZ hexdigestr _clean_one) rrrTrRrGZbuilder wheel_path wheel_nameZ dest_pathZ wheel_hashrFr:r:r;rSs.      z"WheelBuilder._build_one_inside_envcCst|j|jddS)NT)rOZunbuffered_output)rZ setup_py_pathrO)rrr:r:r;_base_setup_argss zWheelBuilder._base_setup_argsc Cs|jdk st|jr*td|jfdSz~td|td|j}|j }| ||j ||jd}W5QRX|rt ||}t t j||t j|||}Wn$tk rtd|jYdSXt j||S)zBuild one InstallRequirement using the PEP 517 build process. Returns path to wheel if successfully built. Otherwise, returns None. NzGCannot build wheel for %s using PEP 517 when --build-options is presentDestination directory: %szBuilding wheel for {} (PEP 517))metadata_directoryFailed building wheel for %s)r]rrNrerrorrWrrrZpep517_backendZsubprocess_runnerZ build_wheelrar3renamer4r_r)rrtempdrRZrunnerZbackendrZnew_namer:r:r;rVs8      zWheelBuilder._build_one_pep517c Cs||}d|jf}t|}td||dd|g|j}|dk rT|d|g7}zt||j|d}Wn8tk r| dt d |jYW5QRdSXt |} t | ||||d } | W5QRSQRXdS) zBuild one InstallRequirement using the "legacy" build process. Returns path to wheel if successfully built. Otherwise, returns None. z Building wheel for %s (setup.py)r\Z bdist_wheelz-dNz --python-tag)cwdspinnerr_r^)rFrGrrBrC)r[rWrrrrNrZunpacked_source_directoryrZfinishr_r3rrrH) rrrarR base_argsZ spin_messagerdZ wheel_argsoutputrFrYr:r:r;rWs8         zWheelBuilder._build_one_legacycCsb||}td|j|ddg}zt||jdWdStk r\td|jYdSXdS)NzRunning setup.py clean for %sZcleanz--all)rcTz Failed cleaning build dir for %sF)r[rr8rWrrrr_)rrreZ clean_argsr:r:r;rXs  zWheelBuilder._clean_onec Cs|r |jr|s|jstg}t|jj}|D]\}t||||jd}|dkrLq,|rt|rd|j|j}qz|j |j}n|j}| ||fq,|sgSt dd dd|Dd}|rtj}tgg} } |D]\}}z t|WnFtk r.} z&t d|j| | |WYqW5d} ~ XYnX|j|||d} | r| ||r|jrrt|jsrtd |||jj|_tt| |_|jjstt|jj |jq| |qW5QRX| rt d d d d| D| rt d d dd| D| S)aBuild wheels. :param should_unpack: If True, after building the wheel, unpack it and replace the sdist with the unpacked version in preparation for installation. :return: True if all the wheels built correctly. )r;r<r=Nz*Building wheels for collected packages: %srcSsg|]\}}|jqSr:rW)rrrpr:r:r;r\sz&WheelBuilder.build..z Building wheel for %s failed: %srQzbad source dir - missing markerzSuccessfully built %sr}cSsg|] }|jqSr:rgrrr:r:r;rszFailed to build %scSsg|] }|jqSr:rgrhr:r:r;rs)!rMrr4rL cache_dirr?r=Zget_ephem_path_for_linkr9Zget_path_for_linkrrr8r_r Zimplementation_tagrrOSErrorrrWrUrrZremove_temporary_sourceZensure_build_locationrKZ build_dirrrr7rZ file_path) rZ requirementsr;Zbuildsetr<rZ ephem_cacherTrRZ build_successZ build_failurer Z wheel_filer:r:r;r#s       zWheelBuilder.build)NNNF)N)N)N)N)F) rrrr1r%rUrSr[rVrWrXrr:r:r:r;rJs   ' %rJ)r=)r=)FNNTNFNT)r1Z __future__rrrrr@r@Zos.pathr3rrrrUrbase64rZ email.parserrZ pip._vendorrZpip._vendor.distlib.scriptsrZpip._vendor.distlib.utilrZpip._vendor.packaging.utilsrZpip._vendor.sixr Z pip._internalr Zpip._internal.exceptionsr r r Zpip._internal.locationsrrZpip._internal.models.linkrZpip._internal.utils.loggingrZ pip._internal.utils.marker_filesrZpip._internal.utils.miscrrrZ$pip._internal.utils.setuptools_buildrZpip._internal.utils.subprocessrrrrZpip._internal.utils.temp_dirrZpip._internal.utils.typingrZpip._internal.utils.uirZpip._internal.utils.unpackingrZpip._internal.utils.urlsrtypingr r!r"r#r$r%r&r'r(r)r*r+Z"pip._vendor.packaging.requirementsr,Zpip._internal.req.req_installr-Z pip._internal.operations.preparer.Zpip._internal.cacher/Zpip._internal.pep425tagsr0rOZInstalledCSVRowr4ZBinaryAllowedPredicaterZ getLoggerrrr<rIrPr[raror2r3rsr{rrrrrrrrrrrrobjectrIr6r?rErHrIrJr:r:r:r;s                  8           =$  4 J :