3 (\@sdZddlmZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZdd l m!Z!m"Z"m#Z#dd l$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9e7rddl:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDddlEmFZFddlGmHZHddlmIZIddlJmKZKmLZLddlMmNZNddlOmPZPddlQmRZRe@eSdfZTdJZUejVeWZXdd ZYdLd"d#ZZd$d%Z[d&d'Z\d(d)Z]e j^d*e j_Z`d+d,Zad-d.Zbd/d0Zcd1d2Zdd3d4ZedMd7d8Zfd9d:Zgd;d<ZhGd=d>d>eiZje j^d?e jkfd@dAZldBdCZmdDdEZndFdGZoGdHdIdIeiZpdS)NzH Support for installing and building the "wheel" binary package format. )absolute_importN)urlsafe_b64encode)Parser) pkg_resources) ScriptMaker)canonicalize_name)StringIO) pep425tags) path_to_url unpack_url)InstallationErrorInvalidWheelFilenameUnsupportedWheel)PIP_DELETE_MARKER_FILENAMEdistutils_scheme)Link) indent_log) LOG_DIVIDERcall_subprocesscaptured_stdout ensure_dirformat_command_args read_chunks)SETUPTOOLS_SHIM) TempDirectory)MYPY_CHECK_RUNNING) open_spinner) DictListOptionalSequenceMappingTupleIOTextAnyIterable) Requirement)InstallRequirement) PipSession) FormatControl PackageFinder)RequirementPreparer) WheelCache) Pep425Tag.cCstjj||jtjjdS)N/)ospathrelpathreplacesep)srcpr8f/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/wheel.pynormpathCsr:c Csvtj}d}t|d2}x*t||dD]}|t|7}|j|q&WWdQRXdt|jjdj d}|t |fS)z5Return (hash, length) for path using hashlib.sha256()rrb)sizeNzsha256=latin1=) hashlibsha256openrlenupdaterdigestdecoderstripstr)r2 blocksizehlengthfblockrEr8r8r9rehashGs   rNcCs6tjddkri}d}n ddi}d}t|||f|S)Nrbnewline)sys version_inforB)namemodenlbinr8r8r9 open_for_csvWs rYcCs|jd}||d<dj|S)zBReplace the Python tag in a wheel file name with a new value. -rO)splitjoin)Z wheelnameZnew_tagpartsr8r8r9replace_python_tagbs r_cCstjj|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) r1r2isfilerBreadline startswithrS executableencodegetfilesystemencodinglinesepreadwrite)r2script firstlineexenamerestr8r8r9 fix_scriptks     rozX^(?P(?P.+?)(-(?P.+?))?) \.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. rZ_rUWHEELzroot-is-purelib: trueTNF) r4r1listdir dist_info_rematchgrouprBr2r]lowerrG)rUwheeldir name_foldeditemrtwheelliner8r8r9root_is_purelibs    r|c stjj|siifSt|<}t}x$|D]}|j|j|jdq*W|jdWdQRXtj j |}|j di}|j di}ddt fdd|j D}t fd d|j D}||fS) N rconsole_scripts gui_scriptscSst|jddjdS)zRget the string representation of EntryPoint, remove space and split on '=' rRr?)rHr4r\)sr8r8r9 _split_epsz"get_entrypoints.._split_epc3s|]}|VqdS)Nr8).0v)rr8r9 sz"get_entrypoints..c3s|]}|VqdS)Nr8)rr)rr8r9rs)r1r2existsrBrrjstripseekr EntryPoint parse_mapgetdictvalues)filenamefpdatar{ entry_pointsconsoleguir8)rr9get_entrypointss      rc sR|sdStjt}x2|D]*}tjj|}tjj|}||j|qWddtjj ddj tj Dj tjj tjjtjfdd|jD}|sdSg}xn|jD]b\}}t|}t|dkrd j|d }n$d jd j|ddd |d}|j dj||qWd} t|dkr8|j | jdn|j | jddj|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|]}tjj|jtjqSr8)r1r2normcaserGr5)rir8r8r9 sz5message_about_scripts_not_on_PATH..PATHrRcs&i|]\}}tjj|kr||qSr8)r1r2r)r parent_dirscripts) not_warn_dirsr8r9 sz5message_about_scripts_not_on_PATH..r/z script {} isrzscripts {} arez, 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}r) collections defaultdictsetr1r2dirnamebasenameaddenvironrr\pathsepappendrrSreitemssortedrCformatr]) rZgrouped_by_dirdestfiler script_nameZwarn_forZ msg_linesZsorted_scriptsZ start_textZ last_line_fmtr8)rr9!message_about_scripts_not_on_PATHs:        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|VqdS)N)rH)rxr8r8r9rsz3sorted_outrows....)tuple)rowr8r8r9sz sorted_outrows..)key)r)outrowsr8r8r9sorted_outrowssrc Csg}x~|D]v}t|dkr*tjdj|t|}|d}|j||}||d<||krrt|\} } | |d<| |d<|jt|q Wx2|D]*} t| \} } |jt | || t | fqWx |D]} |j|| ddfqW|S)z_ :param installed: A map from archive RECORD path to installation RECORD path. rOz,RECORD line has more than three elements: {}rr/rR) rCloggerwarningrlistpoprNrrr:rH) Z old_csv_rows installedchanged generatedlib_dirZinstalled_rowsrZold_pathnew_pathrErKrLr8r8r9get_csv_rows_for_installeds(         rFTc **s|st|||||| d}t| r,|dn|dgg jtjjtjj} itg} |rt4} tj tj dt j | dddWdQRXWdQRXt j| jd1 fd d d2 fd d }|| dstd tjjdd}t|\fdd}xvD]n}d}d}x^tjtjj |D]F}d}|dkrdt}|}tjj ||} ||}|| |d||dqJWq(Wtd|dd_dh_d_ fdd}|_d_jdd}|rdtjkr d|}| jj|tjjdddkrFdt j!dd|f}| jj|dt j!dd|f}| jj|dd D}x|D] }|=qWjd!d}|rdtjkrd"|}| jj|d#t j!dd|f}| jj|d$d D}x|D] }|=qWt"dkrbj#d%d j$D}| j|| rbt%|}|dk rbt j&|t"dkr| jj#d&d j$Dd'ditjjdd(}tjjdd)} t'| d*}!|!j(d+WdQRXt)j*| || j+|tjjdd,}"tjjdd-}#t,|"d.`}$t,|#d/J}%t-j.|$}&t/|&| d0}'t-j0|%}(xt1|'D]})|(j2|)qZWWdQRXWdQRXt)j*|#|"dS)3zInstall a wheel)userhomerootisolatedprefixpurelibplatlibignoreT)forcequietNFcs.t|}t|}||<|r*j|dS)z6Map archive RECORD paths to installation RECORD paths.N)r:r)srcfilermodifiedoldpathnewpath)rrrrwr8r9record_installed\s   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| tjj|rRtj|tj| |tj| }ttdrtj||j|jftj| tjrtj| }|jtjBtjBtjB}tj||d }|r||}| ||qWqWdS) Nr/rz.datarRz .dist-infoz!Multiple .dist-info directories: z, utimeF)rr1walkrClstripr2r5r]r\endswithrrrdrUAssertionErrorrunlinkshutilcopyfilestathasattrrst_atimest_mtimeaccessX_OKst_modeS_IXUSRS_IXGRPS_IXOTHchmod)sourcedestis_basefixerfilterdirsubdirsfilesbasedirdestdirr destsubdirrLrrst permissionsr) data_dirsinfo_dirrreqr8r9clobberdsN             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.exez -script.py z.pyair)rvr)rU matchname)rrr8r9is_entrypoint_wrappersz/move_wheel_files..is_entrypoint_wrapperr)rrrRcs<|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)makerrr8r9_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()) pipENSUREPIP_OPTIONSzpip = altinstallz pip%s = %sr/rOcSsg|]}tjd|r|qS)zpip(\d(\.\d)?)?$)rert)rkr8r8r9r)sz$move_wheel_files.. easy_installzeasy_install = zeasy_install-%s = %scSsg|]}tjd|r|qS)zeasy_install(-\d\.\d)?$)rrt)rrr8r8r9r6scSsg|] }d|qS)z%s = %sr8)rkvr8r8r9r>scSsg|] }d|qS)z%s = %sr8)rrr8r8r9rJsr INSTALLERz INSTALLER.pipraspip RECORDz RECORD.piprzw+)rrrr)F)NN)3rr|rGr1r2r5rrwarningscatch_warningsfilterwarnings compileall compile_dirrdebuggetvaluerr]rrrrorrvariantsset_moderrrrextendmakerrSversionrC make_multiplerrrrBrjrmoverrYcsvreaderrwriterrwriterow)*rUrrwrrr pycompileschemerrZwarn_script_locationrrstdoutrep_filerdatadirrrsubdirrr pip_scriptspecpip_epreasy_install_scripteasy_install_epZgenerated_console_scriptsmsg installertemp_installerinstaller_filerecord temp_record record_in record_outrrrrr8) rrrrrrrrrrrwr9move_wheel_files*s     $F     #                    $r/c CsnyTddtjd|Dd}|jd}tj|}|dj}ttt|j d}|St k rhdSXdS)z Return the Wheel-Version of an extracted wheel, if possible. Otherwise, return None if we couldn't parse / extract it. cSsg|]}|qSr8r8)rdr8r8r9rpsz!wheel_version..Nrrqz Wheel-Versionr) r find_on_path get_metadatarparsestrrrmapintr\ Exception) source_dirdist wheel_datarr8r8r9 wheel_versionhs   r:cCsb|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)rVERSION_COMPATIBLEr]r4rHrr)rrUr8r8r9check_compatibility|s r<c@s:eZdZdZejdejZddZd ddZ d dd Z dS) Wheelz A wheel filez^(?P(?P.+?)-(?P.*?)) ((-(?P\d[^-]*?))?-(?P.+?)-(?P.+?)-(?P.+?) \.whl|\.dist-info)$csjj|}|std||_|jdjdd_|jdjdd_|jd_|jdj d_ |jd j d_ |jd j 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.rUrprZverbuildpyverrabiplatcs.h|]&}jD]}jD]}|||fqqqSr8)abisplats)rryz)selfr8r9 sz!Wheel.__init__..N) wheel_file_rertr rrur4rUrZ build_tagr\ pyversionsrCrD file_tags)rGr wheel_infor8)rGr9__init__s    zWheel.__init__Ncs4dkrtjfdd|jD}|r0t|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|qSr8)index)rc)tagsr8r9rsz+Wheel.support_index_min..)r get_supportedrKmin)rGrPindexesr8)rPr9support_index_minszWheel.support_index_mincCs$|dkrtj}tt|j|jS)z'Is this wheel supported on this system?N)r rQboolr intersectionrK)rGrPr8r8r9 supportedszWheel.supported)N)N) __name__ __module__ __qualname____doc__rcompileVERBOSErIrMrTrWr8r8r8r9r=s r=z([a-z0-9_.]+)-([a-z0-9_.!+-]+)cCst|j|S)zjDetermine whether the string looks like an egg_info. :param s: The string to parse. E.g. foo-2.1 )rUsearch)r _egg_info_rer8r8r9_contains_egg_infosr`cCs|jr dS|jr&|s"tjd|jdS|s.dS|js<|j r@dS|jrT|jj rTdSd|j t |jkrztjd|jdS|j}|j \}}|rt |rdSdS)aZ Return whether to build an InstallRequirement object using the ephemeral cache. :param cache_available: whether a cache directory is available for the autobuilding=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.FTbinaryzCSkipping bdist_wheel for %s, due to binaries being disabled for it.) constraintis_wheelrinforUeditabler7link is_artifactZget_allowed_formatsrsplitextr`)rformat_control autobuildingcache_availablerfbaseextr8r8r9should_use_ephemeral_caches0   rncCs^t|}dj|}|s |d7}n:tjtjkr8|d7}n"|jdsJ|d7}|dj|t7}|S)z1 Format command information for logging. zCommand arguments: {} zCommand output: Nonez'Command output: [use --verbose to show]r}zCommand output: {}{})rrrgetEffectiveLevelloggingDEBUGrr) command_argscommand_output command_desctextr8r8r9format_command_results    rvcCsxt|}|s4dj|j}|t||7}tj|dSt|dkrfdj|j|}|t||7}tj|tjj ||dS)zH Return the path to the wheel in the temporary build directory. z1Legacy build of wheel for {!r} created no files. Nr/zZLegacy build of wheel for {!r} created more than one file. Filenames (choosing first): {} r) rrrUrvrrrCr1r2r])namestemp_dirrrrrsr'r8r8r9get_legacy_build_wheel_path,s     ryc@s\eZdZdZdddZdddZddd Zd d Zdd d ZdddZ ddZ dddZ dS) WheelBuilderz#Build wheels from a RequirementSet.NFcCs8||_||_||_|j|_|p g|_|p*g|_||_dS)N)finderpreparer wheel_cachewheel_download_dir _wheel_dir build_optionsglobal_optionsno_clean)rGr{r|r}rrrr8r8r9rMOs   zWheelBuilder.__init__c Cs"|j|j|||dSQRXdS)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)rGr output_dirrr8r8r9 _build_onecszWheelBuilder._build_onec Cstdd}|jr|j}n|j}|||j|d}|dk rtjj|}tjj||}ytj ||t j d||St k rYnX|j |dSQRXdS)Nrz)kind)rzStored in directory: %s)rZ use_pep517_build_one_pep517_build_one_legacyr2r1rr]rrrrdr6 _clean_one) rGrrrrxZbuilder wheel_path wheel_nameZ dest_pathr8r8r9rms      z"WheelBuilder._build_one_inside_envcCstjddt|jgt|jS)Nz-uz-c)rSrersetup_pyrr)rGrr8r8r9_base_setup_argss zWheelBuilder._base_setup_argsc Cs|jdk st|jr*tjd|jfdSybd|jf|_tjd||jj ||jd}|rt ||}t j t j j||t j j|||}Wn"tk rtjd|jdSXt j 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 presentzBuilding wheel for %s (PEP 517)zDestination directory: %s)metadata_directoryzFailed building wheel for %s)rrrrerrorrU spin_messagerZpep517_backendZ build_wheelr_r1renamer2r]r6)rGrtempdrrnew_namer8r8r9rs*     zWheelBuilder._build_one_pep517c Cs|j|}d|jf}t|}tjd||dd|g|j}|dk rT|d|g7}yt||j|d}Wn,tk r|j dtj d |jdSXt j |} t | ||||d } | SQRXdS) 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)zDestination directory: %s bdist_wheelz-dNz --python-tag)cwdspinnerrzFailed building wheel for %s)rwrxrrrrs)rrUrrrrr setup_py_dirr6finishrr1rrry) rGrrr base_argsrr wheel_argsoutputrwrr8r8r9rs,        zWheelBuilder._build_one_legacyc Cs^|j|}tjd|j|ddg}yt||jddStk rXtjd|jdSXdS)NzRunning setup.py clean for %scleanz--all)rTz Failed cleaning build dir for %sF)rrrdrUrr7r6r)rGrr clean_argsr8r8r9rs  zWheelBuilder._clean_onecCsRg}|jj}t|jp|jj}x4|D],}t||||d}|dkrBq$|j||fq$W|s\gStdd|Dr|jp~|o~|jj} | st t j ddj dd|D|j} t Rgg} } x>|D]4\}} d}|rNtj}| r| j|j}n | j|j}y t|Wn@tk rJ}z"t jd |j|| j|wWYdd}~XnXn|j}|j|||d }|r| j||r|jrtjjtjj |jt rt d |j|j|jj |_t!t"||_|jj#st t$|j|jdd |d q| j|qWWdQRX| r,t j ddj dd| D| rNt j ddj dd| D| S)zBuild wheels. :param unpack: If True, replace the sdist we built from with the newly built wheel, in preparation for installation. :return: True if all the wheels built correctly. )rirjrkNcss|]\}}| VqdS)Nr8)rrp ephem_cacher8r8r9rsz%WheelBuilder.build..z*Building wheels for collected packages: %sz, cSsg|]\}}|jqSr8)rU)rrrpr8r8r9rsz&WheelBuilder.build..z Building wheel for %s failed: %s)rzbad source dir - missing markerF)sessionzSuccessfully built %srcSsg|] }|jqSr8)rU)rrr8r8r9rBszFailed to build %scSsg|] }|jqSr8)rU)rrr8r8r9rGs)%r{rirUrr} cache_dirrnranyrrrdr]rr implementation_tagZget_ephem_path_for_linkrfZget_path_for_linkrOSErrorrrUrr7r1r2rrremove_temporary_sourcebuild_locationr| build_dirrr rcr )rG requirementsrrjbuildsetrirkrrZhave_directory_for_build_cache build_success build_failureZephemrre wheel_filer8r8r9r?s             zWheelBuilder.build)NNF)N)N)N)N)F) rXrYrZr[rMrrrrrrr?r8r8r8r9rzLs  " !rz)r/r)r)FNNTNFNT)qr[ __future__rrr rr@rpos.pathr1rrrrSr base64r email.parserr pip._vendorrpip._vendor.distlib.scriptsrpip._vendor.packaging.utilsrpip._vendor.sixrZ pip._internalr Zpip._internal.downloadr r Zpip._internal.exceptionsr r rZpip._internal.locationsrrZpip._internal.models.linkrZpip._internal.utils.loggingrZpip._internal.utils.miscrrrrrrZ$pip._internal.utils.setuptools_buildrZpip._internal.utils.temp_dirrZpip._internal.utils.typingrZpip._internal.utils.uirZtypingrrrr r!r"r#r$r%r&Z"pip._vendor.packaging.requirementsr'Zpip._internal.req.req_installr(r)Zpip._internal.indexr*r+Z pip._internal.operations.preparer,Zpip._internal.cacher-Zpip._internal.pep425tagsr.rHZInstalledCSVRowr; getLoggerrXrr:rNrYr_ror\r]rsr|rrrrr/r:r<objectr=Ir`rnrvryrzr8r8r8r9s               0             =( 5=6