a [fJ@s@ddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZddlmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd l m!Z!dd l"m#Z#m$Z$dd l%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m,Z0ddl1m2Z3ddl4m5Z5ddl4m6Z7ddl8m9Z9ddl:m;Z;mZ>ddl?m@Z@ddlAmBZBmCZCddlDmEZEddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOddlPmQZQddlRmSZSddlTmUZUmVZVddlWmXZXdd lYmZZZe[e\Z]e^e!d!d"d#Z_Gd$d%d%Z`e`e^d&d'd(ZadS))N)Any CollectionDictIterableListOptionalSequenceUnion) pkg_resources)Marker) Requirement) SpecifierSet)canonicalize_name)Version)parse)Pep517HookCaller) Distribution)BuildEnvironmentNoOpBuildEnvironment)InstallationError) get_scheme)Link)generate_metadata)generate_editable_metadata)install_editable)LegacyInstallFailure)install) install_wheel)load_pyproject_tomlmake_pyproject_path)UninstallPathSet) deprecated)direct_url_for_editabledirect_url_from_link)Hashes) ask_path_exists backup_dir display_pathdist_in_install_pathdist_in_site_packagesdist_in_usersiteget_distributionhide_urlredact_auth_from_url) get_metadata)runner_with_spinner_message) TempDirectory tempdir_kinds)running_under_virtualenv)vcs)metadata_directoryreturncCs|tj}tj|\}}t||}|drJtj}tj |d}n.|dsXJtj }tj |ddd}||||dS)zQReturn a pkg_resources.Distribution for the provided metadata directory. z .egg-inforz .dist-info-) project_namemetadata) rstriposseppathsplitr Z PathMetadataendswithrsplitextZDistInfoDistribution)r4Zdist_dirbase_dirZ dist_dir_namer8Zdist_clsZ dist_namerAA/usr/lib/python3.9/site-packages/pip/_internal/req/req_install.py _get_distBs   rCc@seZdZdZdSeeeeedfeee ee eeeee eee eee ee efee eeeddddZedd d Zedd d Zedd dZeeedddZeedddZeedddZeedddZdTeeeedddZeedddZdUeedddZeedd d!Zeeeed"d#d$Z ddd%d&Z!ddd'd(Z"edd)d*d+Z#eedd,d-Z$eedd.d/Z%eedd0d1Z&eedd2d3Z'eedd4d5Z(ddd6d7Z)ddd8d9Z*ddd:d;Z+ee,ddd?Z/ddd@dAZ0dVeeeddBdCdDZ1dddEdFZ2dWeeee3dGdHdIZ4eeeedJdKdLZ5eeddMdNdOZ6dXe eee7eeeeeeeeeeddP dQdRZ8dS)YInstallRequirementz Represents something that may be installed later on, may have information about where to fetch the relevant requirement and also contains logic for installing the said requirement. FNrA)req comes_fromeditablelinkmarkers use_pep517isolatedinstall_optionsglobal_options hash_options constraintextras user_suppliedpermit_editable_wheelsr5cCs|dust|tsJ|||_||_| |_||_||_d|_d|_|jrp|sRJ|j rpt j t j |j|_|dur|r|jrt|j}||_|_d|_d|_|jr|jj r|jj|_| r| |_n |rdd|jD|_nt|_|dur|r|j}||_d|_d|_d|_d|_|r"|ng|_| r2| ng|_| rB| ni|_d|_ | |_!||_"t#|_$d|_%d|_&g|_'d|_(||_)d|_*dS)NFcSsh|]}t|qSrA)r Z safe_extra.0extrarArArB z.InstallRequirement.__init__..)+ isinstancer rErFrOrGrRlegacy_install_reason source_diris_filer:r<normpathabspathZ file_pathurlrrH original_linkoriginal_link_is_in_wheel_cachelocal_file_pathrPsetZmarkerrI satisfied_byshould_reinstall_temp_build_dirinstall_succeededrLrMrNZpreparedrQrKr build_envr4pyproject_requiresrequirements_to_checkpep517_backendrJZneeds_more_preparation)selfrErFrGrHrIrJrKrLrMrNrOrPrQrRrArArB__init__csX    zInstallRequirement.__init__)r5cCs|jr.t|j}|jrF|dt|jj7}n|jrBt|jj}nd}|jdurf|dt|jj7}|j rt |j tr|j }n |j }|r|d|d7}|S)Nz from {}zz in {}z (from )) rEstrrHformatr-r^rcr'locationrFrX from_pathrksrFrArArB__str__s     zInstallRequirement.__str__cCsd|jjt||jS)Nz<{} object: {} editable={!r}>)ro __class____name__rnrGrkrArArB__repr__szInstallRequirement.__repr__cs>t|t}fddt|D}dj|jjd|dS)z5An un-tested helper for getting state, for debugging.c3s|]}d||VqdS)z{}={!r}N)ro)rTattrZ attributesrArB rWz2InstallRequirement.format_debug..z<{name} object: {{{state}}}>z, )namestate)varssortedrorurvjoin)rknamesr}rArzrB format_debugszInstallRequirement.format_debugcCs|jdurdSt|jjSN)rEr Z safe_namer|rwrArArBr|s zInstallRequirement.namec Cs|js dS|jsJ|j`td}|j|,d|jvWdWdS1sb0YWdn1s0YdS)NFz1Checking if build backend supports build_editableZbuild_editable)rJrjrgr/Zsubprocess_runnerZ_supported_features)rkZrunnerrArArBsupports_pyproject_editables z.InstallRequirement.supports_pyproject_editablecCs|jjSr)rE specifierrwrArArBrszInstallRequirement.specifiercCs$|j}t|dko"tt|jdvS)zReturn whether I am pinned to an exact version. For example, some-package==1.2 is pinned; some-package>1.2 is not. >=====)rlennextiteroperator)rkZ specifiersrArArB is_pinnedszInstallRequirement.is_pinned)extras_requestedr5cs0|sd}jdur(tfdd|DSdSdS)N)c3s|]}jd|iVqdS)rUN)rIZevaluaterSrwrArBr{sz3InstallRequirement.match_markers..T)rIany)rkrrArwrB match_markerss  z InstallRequirement.match_markerscCs t|jS)zReturn whether any known-good hashes are specified as options. These activate --require-hashes mode; hashes specified as part of a URL do not. )boolrNrwrArArBhas_hash_optionssz#InstallRequirement.has_hash_optionsT)trust_internetr5cCsB|j}|r|jn|j}|r:|jr:||jg|jt|S)aReturn a hash-comparer that considers my option- and URL-based hashes to be known-good. Hashes in URLs--ones embedded in the requirements file, not ones downloaded from an index server--are almost peers with ones from flags. They satisfy --require-hashes (whether it was implicitly or explicitly activated) but do not activate it. md5 and sha224 are not allowed in flags, which should nudge people toward good algos. We always OR all hashes together, even ones from URLs. :param trust_internet: Whether to trust URL-based (#md5=...) hashes downloaded from the internet, as by populate_link() ) rNcopyrHr_hash setdefaultZ hash_nameappendr$)rkrZ good_hashesrHrArArBhashes's   zInstallRequirement.hashescCsP|jdurdSt|j}|jrLt|jtr2|j}n |j}|rL|d|7}|S)z8Format a nice indicator to show where this "comes from" Nz->)rErnrFrXrqrrrArArBrq<s     zInstallRequirement.from_path) build_dir autodeleteparallel_buildsr5cCs|dus J|jdur*|jjs"J|jjS|jdurLttjdd|_|jjSt|j}|rn|dt j }t j |st d|t |t j||}|rdnd}t||tjddjS)NT)kindglobally_managed_zCreating directory %sF)r<deleterr)rer<rEr0r1Z REQ_BUILDrr|uuidZuuid4hexr:existsloggerdebugmakedirsr)rkrrrZdir_nameZactual_build_dirZ delete_argrArArBensure_build_locationJs.         z(InstallRequirement.ensure_build_locationcCsn|jdusJ|jdusJ|jdus*Jtt|jdtrDd}nd}td|jd||jdg|_dS)z*Set requirement after generating metadata.NrrrrName)rEr8rZrX parse_versionrr r)rkoprArArB_set_requirementusz#InstallRequirement._set_requirementcCsDt|jd}t|jj|kr"dStd|j||jt||_dS)NrzeGenerating metadata for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)rr8rEr|rwarningr )rkZ metadata_namerArArBwarn_on_mismatching_namesz+InstallRequirement.warn_on_mismatching_name) use_user_siter5cCs|jdurdSt|jj}|s"dS|j}|duo@|jjj|dd}|sd|_|rt|r`d|_qt rt |rt d |j |jqt|rd|_n|jrd|_d|_n||_dS)zFind an installed distribution that satisfies or conflicts with this requirement, and set self.satisfied_by or self.should_reinstall appropriately. NT)Z prereleaseszVWill not install to the user site because it will lack sys.path precedence to {} in {})rEr+r|versionrcontainsrcr*rdr2r)rror7rpr(rG)rkrZ existing_distZexisting_versionZversion_compatiblerArArBcheck_if_existss8  z"InstallRequirement.check_if_existscCs|js dS|jjS)NF)rHis_wheelrwrArArBrszInstallRequirement.is_wheelcCstj|j|jr|jjpdS)Nr)r:r<rrZrHZsubdirectory_fragmentrwrArArBunpacked_source_directorysz,InstallRequirement.unpacked_source_directorycCs(|jsJd|tj|jd}|S)NNo source dir for zsetup.pyrZr:r<rr)rkZsetup_pyrArArB setup_py_pathsz InstallRequirement.setup_py_pathcCs(|jsJd|tj|jd}|S)Nrz setup.cfgr)rkZ setup_cfgrArArBsetup_cfg_pathsz!InstallRequirement.setup_cfg_pathcCs|jsJd|t|jS)Nr)rZrrrwrArArBpyproject_toml_pathsz&InstallRequirement.pyproject_toml_pathcCs^t|j|j|jt|}|dur*d|_dSd|_|\}}}}||_||_t|j||d|_ dS)aALoad the pyproject.toml file. After calling this routine, all of the attributes related to PEP 517 processing for this requirement have been set. In particular, the use_pep517 attribute can be used to determine whether we should follow the PEP 517 or legacy (setup.py) code path. NFT) backend_path) rrJrrrnrirhrrrj)rkZpyproject_toml_dataZrequiresbackendcheckrrArArBrs z&InstallRequirement.load_pyproject_tomlcCsD|jr@|jr@|s@tj|js@tj|js@td|ddS)zCheck that an editable requirement if valid for use with PEP 517/518. This verifies that an editable that has a pyproject.toml either supports PEP 660 or as a setup.py or a setup.cfg zProject z has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be installed in editable mode. Consider using a build backend that supports PEP 660.N) rGrJrr:r<isfilerrrrwrArArBisolated_editable_sanity_checks   z1InstallRequirement.isolated_editable_sanity_checkcCs|js J|jrZ|jdusJ|jrF|jrF|rFt|j|jd|_qt |j|jd|_n*t |j|j |j |j |jp|d|jd|_|js|n||dS)zEnsure that project metadata is available. Under PEP 517 and PEP 660, call the backend hook to prepare the metadata. Under legacy processing, call setup.py egg-info. N)rgrzfrom )rgrrZrKZdetails)rZrJrjrGrRrrrgr4rgenerate_metadata_legacyrrrKr|rHrrassert_source_matches_versionrwrArArBprepare_metadatas8     z#InstallRequirement.prepare_metadatacCst|dst||_|jS)N _metadata)hasattrr.get_distrrwrArArBr8Bs zInstallRequirement.metadatacCs t|jSr)rCr4rwrArArBrIszInstallRequirement.get_distcCsR|js J|jd}|jjr8||jjvr8td||ntdt|j||dS)Nrz'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)rZr8rErrrrr')rkrrArArBrLs  z0InstallRequirement.assert_source_matches_version) parent_dirrrr5cCs |jdur|j|||d|_dS)aAEnsure that a source_dir is set. This will create a temporary build dir if the name of the requirement isn't known yet. :param parent_dir: The ideal pip parent_dir for the source_dir. Generally src_dir for editables and build_dir for sdists. :return: self.source_dir N)rr)rZr)rkrrrrArArBensure_has_source_dir^s  z(InstallRequirement.ensure_has_source_dircCs|jstd|jdS|js"J|js,J|jjdkrCannot update repository at %s; repository location is unknownfilezUnsupported VCS URL )r^) rHrrrZrGschemer3Zget_backend_for_schemer^r,Zobtain)rkZ vcs_backendZ hidden_urlrArArBupdate_editableus    z"InstallRequirement.update_editable) auto_confirmverboser5cCsR|js Jt|jj}|s,td|jdStd|t|}||||S)a Uninstall the distribution currently satisfying this requirement. Prompts before removing or modifying files unless ``auto_confirm`` is True. Refuses to delete or modify files outside of ``sys.prefix`` - thus uninstallation within a virtual environment can only modify that virtual environment, even if the virtualenv is linked to global site-packages. z#Skipping %s as it is not installed.NzFound existing installation: %s) rEr+r|rrinfor Z from_distremove)rkrrZdistZuninstalled_pathsetrArArB uninstalls     zInstallRequirement.uninstall)r< parentdirrootdirr5cCs8tttddd}tj||}|||}|jd|S)N)r|prefixr5cSsN||tjjs&Jd|d||t|dd}|tjjd}|S)Nzname z doesn't start with prefix r/) startswithr:r<r;rreplace)r|rrArArB_clean_zip_names z=InstallRequirement._get_archive_name.._clean_zip_namer)rnr:r<rr|)rkr<rrrr|rArArB_get_archive_names z$InstallRequirement._get_archive_name)rr5cCs|js J|durdSd}d|j|jd}tj||}tj|rtdt |d}|dkrjd}nj|d krt d t |t |nF|d krt |}t d t |t |t||n|d krtd|sdStj|d tjdd}|tjtj|j}t|D]~\} } } | D]6} |j| | |d} t| d}d|_||dq$| D]0}|j|| |d}tj| |}|||q`qWdn1s0Yt dt |dS)z}Saves archive to provided build_dir. Used for saving downloaded VCS requirements as part of `pip download`. NTz {}-{}.ziprz8The file {} exists. (i)gnore, (w)ipe, (b)ackup, (a)bort )iwbarFrz Deleting %srzBacking up %s to %sr)Z allowZip64)rrrirzSaved %s)rZror|r8r:r<rrr%r'rrrr&shutilmovesysexitzipfileZipFile ZIP_DEFLATEDnormcaser]rwalkrZZipInfoZ external_attrZwritestrwriter)rkrZcreate_archive archive_nameZ archive_pathZresponseZ dest_fileZ zip_outputdirdirpathdirnames filenamesdirnameZ dir_arcnameZzipdirfilenameZ file_arcnamerArArBarchivesr    4zInstallRequirement.archive) rLrMroothomerwarn_script_locationr pycompiler5c Cst|j||||j|d} |dur$|ng}|jrd|jsdt||||||j|j|j|j|jd d|_ dS|jr|j stJd} |jrt |j} n|j rt |j |j|j} t|j|j | t|j||| |jdd|_ dSt||j}t||j}z8t|||||||| |j|j|j|j|jt|jd} WnLtyV} zd|_ | jWYd} ~ n$d} ~ 0typd|_ Yn0| |_ | r|jdkrtd|jd ddd dS) N)userrrrKr)rrrr|rrKrgrT)rreq_descriptionrr direct_urlZ requested)rLrMrrrrrrrrKZreq_namergrrFi zg{} was installed using the legacy 'setup.py install' method, because a wheel could not be built for it.z+to fix the wheel build issue reported abovereasonZ replacementZgone_inZissue)rr|rKrGrinstall_editable_legacyrrgrrfrar"r_r#rZr`rrnrErQlistrMrLinstall_legacyr __cause__ ExceptionrYr!ro) rkrLrMrrrrrrrrsuccessexcrArArBrs         zInstallRequirement.install) FNNNFNNNFrAFF)N)T)FF)FF)NNNNTFT)9rv __module__ __qualname____doc__rr r rnrrr rrrrlrtrxrpropertyr| functools lru_cacherr rrrrrr$rrqrrrrrrrrrrrrrr8rrrrrr rrrrrrArArArBrD\s    j     +.)   F rD)rEr5cCs>d}|jsd}n|jrd}n |jr&d}|r:tddddd|S) Nrz3Unnamed requirements are not allowed as constraintsz4Editable requirements are not allowed as constraintszConstraints cannot have extrasaConstraints are only allowed to take the form of a package name and a version specifier. Other forms were originally permitted as an accident of the implementation, but were undocumented. The new implementation of the resolver no longer supports these forms.z+replacing the constraint with a requirementi r)r|rGrPr!)rEZproblemrArArBcheck_invalid_constraint_typebsr)brZloggingr:rrrrtypingrrrrrrrr Z pip._vendorr Zpip._vendor.packaging.markersr Z"pip._vendor.packaging.requirementsr Z pip._vendor.packaging.specifiersr Zpip._vendor.packaging.utilsrZpip._vendor.packaging.versionrrrZpip._vendor.pep517.wrappersrZpip._vendor.pkg_resourcesrZpip._internal.build_envrrZpip._internal.exceptionsrZpip._internal.locationsrZpip._internal.models.linkrZ'pip._internal.operations.build.metadatarZ0pip._internal.operations.build.metadata_editablerZ.pip._internal.operations.build.metadata_legacyrZ0pip._internal.operations.install.editable_legacyrrZ'pip._internal.operations.install.legacyrrrZ&pip._internal.operations.install.wheelrZpip._internal.pyprojectrrZpip._internal.req.req_uninstallr Zpip._internal.utils.deprecationr!Z&pip._internal.utils.direct_url_helpersr"r#Zpip._internal.utils.hashesr$Zpip._internal.utils.miscr%r&r'r(r)r*r+r,r-Zpip._internal.utils.packagingr.Zpip._internal.utils.subprocessr/Zpip._internal.utils.temp_dirr0r1Zpip._internal.utils.virtualenvr2Zpip._internal.vcsr3Z getLoggerrvrrnrCrDrrArArArBs`(                      ,