ReM @s(dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z mZmZmZmZmZddlmZddlmZdd lmZdd lmZmZmZmZdd lmZdd l m!Z!dd l"m#Z#ddl$m%Z%e!rkddl&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,ddlm-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddlm8Z8ere,dde'e9e(e9ge(e9fde:iddZ;nUe,dde'e9e9gdfde'e9e(e9ge(e9fde:de:iddZ;ej<e=Z>dd Z?d!d"Z@Gd#d$d$eAZBddd%d&ZCd'd(ZDd)d*ZEddd+d,ZFddd-d.ZGd/d0ZHd1d2ZIGd3d4d4eAZJdS)5z)Prepares a distribution for installation N)PY2))make_distribution_for_install_requirement)InstalledDistribution)DirectoryUrlHashUnsupported HashMismatch HashUnpinnedInstallationErrorNetworkConnectionErrorPreviousBuildDirErrorVcsHashUnsupported) copy2_fixed) MissingHashes) indent_log) display_pathhide_urlpath_to_displayrmtree) TempDirectory)MYPY_CHECK_RUNNING) unpack_file)vcs)CallableListOptionalTuple) TypedDict)AbstractDistribution) PackageFinder)Link) Downloader)InstallRequirement)RequirementTracker)HashesCopytreeKwargsignoresymlinkstotalF copy_functionignore_dangling_symlinksc Cs7t|}|j||j||WdQRX|S)z-Prepare a distribution for installation. N)rtrackprepare_distribution_metadata)req req_trackerfinderbuild_isolation abstract_distr0/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/operations/prepare.py_get_prepared_distributionPs r2cCsDtj|j}|dk s$t|j|dt|jdS)Nurl)rget_backend_for_schemeschemeAssertionErrorunpackrr3)linklocation vcs_backendr0r0r1unpack_vcs_link_sr;c@seZdZddZdS)FilecCs||_||_dS)N)path content_type)selfr=r>r0r0r1__init__gs z File.__init__N)__name__ __module__ __qualname__r@r0r0r0r1r<fs r<cCstdddd}d}|r3t|||}|rU|}tj|d}nt|||j|\}}t||S)Nkindr7globally_managedTr)r_check_download_dir mimetypes guess_type_download_http_urlr=r<)r8 downloader download_dirhashestemp_diralready_downloaded_path from_pathr>r0r0r1 get_http_urlmsrPcCshyt||WnPtjk rc}z-tjdt|t|t|WYdd}~XnXdS)zCopying special files is not supported, but as a convenience to users we skip errors copying them. This supports tools that may create e.g. socket files in the project source directory. z>Ignoring special file error '%s' encountered copying %s to %s.N)r shutilSpecialFileErrorloggerwarningstrr)srcdester0r0r1_copy2_ignoring_special_filess  rYcstjj|}tjj|tjj|fdd}td|dd}tsst|d.ignorer$r%Tr') rZr=r[basenamedirnamedictrrYrQcopytree)r_targettarget_abspathr$kwargsr0)r_r`rar1_copy_source_trees ricCsid}|rt|||}|r-|}n |j}|rI|j|tj|d}t||S)z,Get file and optionally check its hash. Nr)rF file_pathcheck_against_pathrGrHr<)r8rKrLrNrOr>r0r0r1 get_file_urls    rlcCs|jrt||dS|jrVtjj|rBt|t|j|dS|j rwt ||d|}nt |||d|}|j st |j||j|S)a_Unpack link into location, downloading if required. :param hashes: A Hashes object, one of whose embedded hashes must match, or HashMismatch will be raised. If the Hashes is empty, no matches are required, and unhashable types of requirements (like VCS ones, which would ordinarily raise HashUnsupported) are allowed. NrL)is_vcsr;is_existing_dirrZr=isdirrrirjis_filerlrPis_wheelrr>)r8r9rJrKrLfiler0r0r1 unpack_urls$       rsc Cs||}tjj||j}t|d(}x|jD]}|j|q@WWdQRX|rq|j|||jj j ddfS)z6Download link url into temp_dir using provided sessionwbNz content-type) rZr=joinfilenameopenchunkswriterkresponseheadersget)r8rJrMrLdownloadrj content_filechunkr0r0r1rIs  rIc Cstjj||j}tjj|s.dStjd||ry|j|Wn3tk rtj d|tj |dSYnX|S)z Check download_dir for previously downloaded file with correct hash If a correct file is found return its path else None NzFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.) rZr=rvrwexistsrSinforkrrTunlink)r8rKrL download_pathr0r0r1rF#s   rFcseZdZdZfddZeddZddZdd Zd d Z d d dZ ddZ ddZ S)RequirementPreparerzPrepares a Requirement c sqtt|j||_||_||_||_||_||_||_ ||_ | |_ | |_ dS)N) superrr@src_dir build_dirr,rJr-rKwheel_download_dirr.require_hashes use_user_site) r?rrKrrr.r,rJr-rr) __class__r0r1r@As         zRequirementPreparer.__init__cCsO|js dStjj|jr&dStjdtdj|jdS)NFTz!Could not find download directoryz0Could not find or access download directory '{}')rKrZr=rrScriticalrformat)r?r0r0r1_download_should_savens  z)RequirementPreparer._download_should_savecCsN|jjr1|jj}tjdt|ntjd|jpF|dS)zLog the way the link prepared.z Processing %sz Collecting %sN)r8rprjrSrrr+)r?r+r=r0r0r1_log_preparing_link|s  z'RequirementPreparer._log_preparing_linkcCs|jjrdS|jdks%t|j|jddd|tjjtjj |jdrt dj ||jdS)z1Ensure source_dir of a linked InstallRequirement.N autodeleteTparallel_buildszsetup.pyzpip can't proceed with requirements '{}' due to apre-existing build directory ({}). This is likely due to a previous installation that failed . pip is being responsible and not assuming it can delete this. Please delete it and try again.) r8rq source_dirr6ensure_has_source_dirrrZr=rrvr r)r?r+rKrr0r0r1_ensure_link_req_src_dirs  $z,RequirementPreparer._ensure_link_req_src_dircCs|js|jddS|jjr.t|jjrFt|jdkrh|j rht |jddpt S)Ntrust_internetTF) rrLr8rmr rnr original_link is_pinnedrr )r?r+r0r0r1_get_linked_req_hashess     z*RequirementPreparer._get_linked_req_hashesFc Cs|jst|j}|j||jrC|jrC|j}n |j}t\|j|||y.t||j |j |d|j |}Wn@t k r}z t dj|||WYdd}~XnX|r|j|_t||j|j|j}|r|jr,tjdn_|rtjj||j}tjj|stj|j|t|} tjd| |jr|j r|j!|jWdQRX|S)z3Prepare a requirement to be obtained from req.link.rLzDCould not install requirement {} because of HTTP error {} for URL {}Nz*Link is a directory, ignoring download_dirzSaved %s)"r8r6rrqrrKrrrsrrJrr rrr=local_file_pathr2r,r-r.rnrSrrZrvrwrrQcopyrrrmarchive) r?r+rr8rK local_fileexcr/download_locationrr0r0r1prepare_linked_requirementsD     %      z.RequirementPreparer.prepare_linked_requirementc Cs|jstdtjd|t|jrMtdj||j|j |j |j t ||j |j|j}|j r|j|j|j|jWdQRX|S)z(Prepare an editable requirement z-cannot prepare a non-editable req as editablez Obtaining %szoThe editable requirement {} cannot be installed when requiring hashes, because there is no single file to hash.N)editabler6rSrrrrrrrupdate_editablerr2r,r-r.rrKcheck_if_existsr)r?r+r/r0r0r1prepare_editable_requirements    z0RequirementPreparer.prepare_editable_requirementc Cs|jstd|dk s9tdj|jtjd|||jjt'|jrutjdt |}WdQRX|S)z1Prepare an already-installed requirement z(req should have been satisfied but isn'tNzAdid not get skip reason skipped but req.satisfied_by is set to {}zRequirement %s: %s (%s)zSince it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.) satisfied_byr6rrSrversionrrdebugr)r?r+ skip_reasonr/r0r0r1prepare_installed_requirements  z1RequirementPreparer.prepare_installed_requirement) rArBrC__doc__r@propertyrrrrrrrr0r0)rr1r=s -  !4 r)KrloggingrGrZrQZpip._vendor.sixrpip._internal.distributionsr%pip._internal.distributions.installedrpip._internal.exceptionsrrrrr r r pip._internal.utils.filesystemr pip._internal.utils.hashesr pip._internal.utils.loggingrpip._internal.utils.miscrrrrpip._internal.utils.temp_dirrpip._internal.utils.typingrpip._internal.utils.unpackingrpip._internal.vcsrtypingrrrrZmypy_extensionsrr"pip._internal.index.package_finderrpip._internal.models.linkrpip._internal.network.downloadrZpip._internal.req.req_installr pip._internal.req.req_trackerr!r"rUboolr# getLoggerrArSr2r;objectr<rPrYrirlrsrIrFrr0r0r0r1sl    4 ""         ""+