o
    c                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dl m!Z! d dl"m#Z#m$Z$ d dl%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m6Z: d dl;m<Z= d dl>m?Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZImJZJ d dlKmLZLmMZM d dlNmOZO d dlPmQZQmRZRmSZSmTZTmUZUmVZV d dlWmXZX d dlYmZZZ d d l[m\Z\m]Z] d d!l^m_Z_ d d"l`maZa ebecZdG d#d$ d$Zed%eed&effd'd(Zgd)e
d*eee d+efd&ehfd,d-Zid.eef d*eee d&ehfd/d0ZjG d1d2 d2eZkd)e
d*eee d3ekd&dfd4d5ZldS )6    N)Enum)Values)Any
CollectionDictIterableListOptionalSequenceUnion)Marker)Requirement)SpecifierSet)canonicalize_name)Version)parse)BuildBackendHookCaller)BuildEnvironmentNoOpBuildEnvironment)InstallationErrorLegacyInstallFailure)
get_scheme)BaseDistributionget_default_environmentget_directory_distributionget_wheel_distribution)FilesystemWheel)	DirectUrl)Link)generate_metadata)generate_editable_metadata)install_editable)install)install_wheel)load_pyproject_tomlmake_pyproject_path)UninstallPathSet)LegacyInstallReason
deprecated)direct_url_for_editabledirect_url_from_link)Hashes) ConfiguredBuildBackendHookCallerask_path_exists
backup_dirdisplay_pathhide_urlredact_auth_from_url
safe_extra)runner_with_spinner_message)TempDirectorytempdir_kinds)running_under_virtualenv)vcsc                !   @   s@  e Zd ZdZ													didee deeed f  dedee	 d	ee
 d
ee dedeee  deee  deeeee f  deeeef  dedee dededdf ddZdefddZdefddZdefddZedee fddZe defdd Zedefd!d"Zedefd#d$Zdjd%eee  defd&d'Zedefd(d)Zdkd+edefd,d-Zdee fd.d/Zd0ed1ed2edefd3d4Z dld5d6Z!dld7d8Z"d9eddfd:d;Z#edefd<d=Z$edefd>d?Z%edefd@dAZ&edefdBdCZ'edefdDdEZ(dldFdGZ)dldHdIZ*dldJdKZ+ede,fdLdMZ-de.fdNdOZ/dldPdQZ0		dmdRed1ed2eddfdSdTZ1dldUdVZ2	dmdWedXedee3 fdYdZZ4d[ed\ed]edefd^d_Z5d0ee ddfd`daZ6					*		*dndee dee7e  dbee dcee ddee deed9edfeddfdgdhZ8dS )oInstallRequirementz
    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.
    FN req
comes_fromeditablelinkmarkers
use_pep517isolatedinstall_optionsglobal_optionshash_optionsconfig_settings
constraintextrasuser_suppliedpermit_editable_wheelsreturnc                 C   s  |d u st |tsJ ||| _|| _|| _|| _|| _d | _d | _| jr8|s)J |j	r8t
jt
j|j| _|d u rF|rF|jrFt|j}| | _| _d| _d | _d | _| jra| jj	ra| jj| _|rg|| _n|rsdd |jD | _nt | _|d u r|r|j}|| _d | _d| _d | _d | _|r|ng | _|	r|	ng | _|
r|
ni | _ || _!d| _"|| _#|| _$t% | _&d | _'d | _(g | _)d | _*|| _+d| _,d S )NFc                 S   s   h | ]}t |qS r:   r2   .0extrar:   r:   J/opt/certbot/lib/python3.10/site-packages/pip/_internal/req/req_install.py	<setcomp>   s    z.InstallRequirement.__init__.<locals>.<setcomp>)-
isinstancer   r;   r<   rF   r=   rI   legacy_install_reason
source_diris_fileospathnormpathabspath	file_pathurlr   r>   original_linkoriginal_link_is_in_wheel_cachedownload_infolocal_file_pathrG   setmarkerr?   satisfied_byshould_reinstall_temp_build_dirinstall_succeededrB   rC   rD   rE   preparedrH   rA   r   	build_envmetadata_directorypyproject_requiresrequirements_to_checkpep517_backendr@   needs_more_preparation)selfr;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   r:   r:   rN   __init__M   s\   


zInstallRequirement.__init__c                 C   s   | j rt| j }| jr|dt| jj7 }n| jr!t| jj}nd}| jd ur>| jjd ur5t| jj}nd}|d| 7 }| j	rZt
| j	trK| j	}n| j	 }|rZ|d| d7 }|S )Nz from {}z<InstallRequirement>z<memory> in z (from ))r;   strr>   formatr1   rY   r`   locationr/   r<   rP   	from_path)rk   srq   r<   r:   r:   rN   __str__   s(   


zInstallRequirement.__str__c                 C   s   d | jjt| | jS )Nz<{} object: {} editable={!r}>)rp   	__class____name__ro   r=   rk   r:   r:   rN   __repr__   s   zInstallRequirement.__repr__c                    s>   t |  t } fddt|D }dj| jjd|dS )z5An un-tested helper for getting state, for debugging.c                 3   s     | ]}d  | | V  qdS )z{}={!r}N)rp   )rL   attr
attributesr:   rN   	<genexpr>   s    z2InstallRequirement.format_debug.<locals>.<genexpr>z<{name} object: {{{state}}}>z, )namestate)varssortedrp   ru   rv   join)rk   namesr~   r:   rz   rN   format_debug   s   zInstallRequirement.format_debugc                 C   s   | j d u rd S | j jS N)r;   r}   rw   r:   r:   rN   r}      s   
zInstallRequirement.namec              	   C   s   | j sdS | js
J | j1 td}| j| d| j v W  d    W  d    S 1 s1w   Y  W d    d S 1 sAw   Y  d S )NFz1Checking if build backend supports build_editablebuild_editable)r@   ri   re   r4   subprocess_runner_supported_features)rk   runnerr:   r:   rN   supports_pyproject_editable   s   
"z.InstallRequirement.supports_pyproject_editablec                 C   s   | j jS r   )r;   	specifierrw   r:   r:   rN   r      s   zInstallRequirement.specifierc                 C   s$   | j }t|dkott|jdv S )zReturn whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
           >   =====)r   lennextiteroperator)rk   
specifiersr:   r:   rN   	is_pinned   s   zInstallRequirement.is_pinnedextras_requestedc                    s,   |sd} j d urt fdd|D S dS )N) c                 3   s     | ]} j d |iV  qdS )rM   N)r?   evaluaterK   rw   r:   rN   r|   
  s    
z3InstallRequirement.match_markers.<locals>.<genexpr>T)r?   any)rk   r   r:   rw   rN   match_markers  s   
z InstallRequirement.match_markersc                 C   s
   t | jS )zReturn whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        )boolrD   rw   r:   r:   rN   has_hash_options  s   
z#InstallRequirement.has_hash_optionsTtrust_internetc                 C   sB   | j  }|r
| jn| j}|r|jr||jg |j t|S )a  Return 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()

        )	rD   copyr>   rZ   hash
setdefault	hash_nameappendr+   )rk   r   good_hashesr>   r:   r:   rN   hashes  s
   

zInstallRequirement.hashesc                 C   sP   | j du rdS t| j }| jr&t| jtr| j}n| j }|r&|d| 7 }|S )z8Format a nice indicator to show where this "comes from" Nz->)r;   ro   r<   rP   rr   )rk   rs   r<   r:   r:   rN   rr   /  s   


zInstallRequirement.from_path	build_dir
autodeleteparallel_buildsc                 C   s   |d usJ | j d ur| j jsJ | j jS | jd u r&ttjdd| _ | j jS t| j}|r7| dt	 j
 }tj|sHtd| t| tj||}|rSd nd}t||tjddjS )NT)kindglobally_managed_zCreating directory %sF)rU   deleter   r   )rb   rU   r;   r5   r6   	REQ_BUILDr   r}   uuiduuid4hexrT   existsloggerdebugmakedirsr   )rk   r   r   r   dir_nameactual_build_dir
delete_argr:   r:   rN   ensure_build_location=  s2   



z(InstallRequirement.ensure_build_locationc                 C   sn   | j du sJ | jdusJ | jdusJ tt| jd tr"d}nd}td| jd || jd g| _ dS )z*Set requirement after generating metadata.Nr   r   r   r   Name)r;   metadatarR   rP   parse_versionr   r   r   )rk   opr:   r:   rN   _set_requirementh  s   
z#InstallRequirement._set_requirementc                 C   sD   t | jd }t | jj|krd S td| j|| j t|| _d S )Nr   zeGenerating metadata for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)r   r   r;   r}   r   warningr   )rk   metadata_namer:   r:   rN   warn_on_mismatching_name~  s   z+InstallRequirement.warn_on_mismatching_nameuse_user_sitec                 C   s   | j du rdS t | j j}|sdS | j jj|jdd}|sGd| _|rB|jr,d| _	dS t
 r>|jr@td|j d|j dS dS d| _	dS | jrRd| _	d| _dS || _dS )zFind an installed distribution that satisfies or conflicts
        with this requirement, and set self.satisfied_by or
        self.should_reinstall appropriately.
        NT)prereleaseszNWill not install to the user site because it will lack sys.path precedence to rm   )r;   r   get_distributionr}   r   containsversionr`   in_usersitera   r7   in_site_packagesr   raw_namerq   r=   )rk   r   existing_distversion_compatibler:   r:   rN   check_if_exists  s8   




z"InstallRequirement.check_if_existsc                 C   s   | j sdS | j jS )NF)r>   is_wheelrw   r:   r:   rN   r     s   zInstallRequirement.is_wheelc                 C   s   t j| j| jr| jjpdS )Nr   )rT   rU   r   rR   r>   subdirectory_fragmentrw   r:   r:   rN   unpacked_source_directory  s   z,InstallRequirement.unpacked_source_directoryc                 C   (   | j s
J d|  tj| jd}|S )NNo source dir for zsetup.pyrR   rT   rU   r   r   )rk   setup_pyr:   r:   rN   setup_py_path     z InstallRequirement.setup_py_pathc                 C   r   )Nr   z	setup.cfgr   )rk   	setup_cfgr:   r:   rN   setup_cfg_path  r   z!InstallRequirement.setup_cfg_pathc                 C   s   | j s
J d|  t| jS )Nr   )rR   r%   r   rw   r:   r:   rN   pyproject_toml_path  s   
z&InstallRequirement.pyproject_toml_pathc                 C   s`   t | j| j| jt| }|du rd| _dS d| _|\}}}}|| _|| _t| | j||d| _	dS )aA  Load 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)
r$   r@   r   r   ro   rh   rg   r,   r   ri   )rk   pyproject_toml_datarequiresbackendcheckr   r:   r:   rN   r$     s    z&InstallRequirement.load_pyproject_tomlc                 C   sT   | j r | jr"|  s$tj| js&tj| js(td|  ddS dS dS dS dS )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
        zProject 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)	r=   r@   r   rT   rU   isfiler   r   r   rw   r:   r:   rN   isolated_editable_sanity_check  s   
z1InstallRequirement.isolated_editable_sanity_checkc                 C   s   | j sJ | jpd| j }| jr8| jdusJ | jr-| jr-|  r-t| j	| j|d| _
nt| j	| j|d| _
nt| j	| j| j| j|d| _
| jsN|   n|   |   dS )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.
        zfrom N)re   r   details)re   r   rR   rA   r   )rR   r}   r>   r@   ri   r=   rI   r   r    re   rf   r   generate_metadata_legacyr   r   rA   r   r   assert_source_matches_version)rk   r   r:   r:   rN   prepare_metadata  s>   


	
z#InstallRequirement.prepare_metadatac                 C   s   t | ds|  j| _| jS )N	_metadata)hasattrget_distr   r   rw   r:   r:   rN   r   1  s   
zInstallRequirement.metadatac                 C   sB   | j rt| j S | jr| jrtt| jt| jS td|  d)NzInstallRequirement zC has no metadata directory and no wheel: can't make a distribution.)	rf   r   r]   r   r   r   r   r}   AssertionErrorrw   r:   r:   rN   r   8  s   

zInstallRequirement.get_distc                 C   sT   | j sJ | jd }| jjr|| jjvrtd| | d S tdt| j ||  d S )Nr   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)rR   r   r;   r   r   r   r   r/   )rk   r   r:   r:   rN   r   D  s   

z0InstallRequirement.assert_source_matches_version
parent_dirc                 C   s$   | j du r| j|||d| _ dS dS )aA  Ensure 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)r   r   )rR   r   )rk   r   r   r   r:   r:   rN   ensure_has_source_dirV  s   
z(InstallRequirement.ensure_has_source_dirc                 C   s   | j std| j d S | jsJ | jsJ | j jdkrd S t| j j}|s0J d| j j t	| j j}|j
| j|dd d S )Nz>Cannot update repository at %s; repository location is unknownfilezUnsupported VCS URL r   )rY   	verbosity)r>   r   r   rR   r=   schemer8   get_backend_for_schemerY   r0   obtain)rk   vcs_backend
hidden_urlr:   r:   rN   update_editablem  s   

z"InstallRequirement.update_editableauto_confirmverbosec                 C   sV   | j sJ t | j j}|std| j dS td| 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.NzFound existing installation: %s)
r;   r   r   r}   r   r   infor&   	from_distremove)rk   r   r   distuninstalled_pathsetr:   r:   rN   	uninstall  s   

zInstallRequirement.uninstallrU   	parentdirrootdirc                 C   s<   dt dt dt fdd}tj||}|||}| jd | S )Nr}   prefixrJ   c                 S   sN   |  |tjj sJ d| d|| t|d d  } | tjjd} | S )Nzname z doesn't start with prefix r   /)
startswithrT   rU   sepr   replace)r}   r   r:   r:   rN   _clean_zip_name  s   
z=InstallRequirement._get_archive_name.<locals>._clean_zip_namer   )ro   rT   rU   r   r}   )rk   rU   r   r   r   r}   r:   r:   rN   _get_archive_name  s   
z$InstallRequirement._get_archive_namec                 C   s  | j sJ |du rdS d}d| j| jd }tj||}tj|rjtdt	|d}|dkr5d}n5|d	krGt
d
t	| t| n#|dkrat|}t
dt	|t	| t|| n	|dkrjtd |sndS tj|d	tjdd}|U tjtj| j}t|D ]<\}	}
}|
D ]}| j||	|d}t|d }d|_||d q|D ]}| j||	|d}tj|	|}||| qqW d   n1 sw   Y  t
dt	| dS )z}Saves archive to provided build_dir.

        Used for saving downloaded VCS requirements as part of `pip download`.
        NTz	{}-{}.zipr   z8The file {} exists. (i)gnore, (w)ipe, (b)ackup, (a)bort )iwbar   Fr   zDeleting %sr  zBacking up %s to %sr  )
allowZip64)r   r   r   i  r   zSaved %s)rR   rp   r}   r   rT   rU   r   r   r-   r/   r   r   r   r.   shutilmovesysexitzipfileZipFileZIP_DEFLATEDnormcaserW   r   walkr   ZipInfoexternal_attrwritestrwriter   )rk   r   create_archivearchive_namearchive_pathresponse	dest_file
zip_outputdirdirpathdirnames	filenamesdirnamedir_arcnamezipdirfilenamefile_arcnamer:   r:   rN   archive  sv   


zInstallRequirement.archiveroothomer   warn_script_location	pycompilec	                 C   s  t | j|||| j|d}	|d ur|ng }| jr2| js2t|||||| j| j| j| j| jd
 d| _	d S | jrh| j
s:J d }
| jrEt| j}
n| jrQt| j| j| j}
t| j| j
|	t| j|||
| jd d| _	d S t|| j }t|| j }z,| jd ur| jjr| j| j t||||||||	| j| j| j| j| jt| jd}W n ty } zd| _	|d }~w ty   d| _	 w || _	|r| jd ur| jjr| j| j d S d S d S d S )N)userr#  r"  rA   r   )r   r#  r   r}   r   rA   re   r   T)r   req_descriptionr%  r$  
direct_url	requested)rB   rC   r"  r#  r   r   r%  r   r   rA   req_namere   r   r'  F)r   r}   rA   r=   r   install_editable_legacyr   re   r   rc   r]   r)   rZ   r*   rR   r[   r#   ro   r;   rH   listrC   rB   rQ   emit_before_installemit_deprecationinstall_legacyr   	Exceptionemit_after_success)rk   rB   rC   r"  r#  r   r$  r   r%  r   r(  successexcr:   r:   rN   r"     s   	

	
zInstallRequirement.install)FNNNFNNNNFr:   FFr   )T)rJ   N)FF)NNNNTFT)9rv   
__module____qualname____doc__r	   r   r   ro   r   r   r   r   r   r   rl   rt   rx   r   propertyr}   	functools	lru_cacher   r   r   r   r   r   r   r+   r   rr   r   r   r   r   r   r   r   r   r   r$   r   r   r   r   r   r   r   r   r   r&   r   r   r!  r
   r"   r:   r:   r:   rN   r9   F   s   

	


o	

+
&


,



F
	
r9   r;   rJ   c                 C   s>   d}| j sd}n| jrd}n| jrd}|rtddd dd |S )	Nr   z3Unnamed requirements are not allowed as constraintsz4Editable requirements are not allowed as constraintszConstraints cannot have extrasa  Constraints 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   )reasonreplacementgone_inissue)r}   r=   rG   r(   )r;   problemr:   r:   rN   check_invalid_constraint_typeZ  s   r?  optionsreqsoptionc                 C   s0   t | |d rdS |D ]}t ||d r dS q
dS )NTF)getattr)r@  rA  rB  r;   r:   r:   rN   _has_optionw  s   rD  rB   c                 C   s$   |D ]}| s	|j r|js dS qdS )NFT)rB   r@   )rB   rA  r;   r:   r:   rN   _install_option_ignored  s
   rE  c                   @   s   e Zd ZdZdZdZdS )LegacySetupPyOptionsCheckModer         N)rv   r4  r5  INSTALLWHEELDOWNLOADr:   r:   r:   rN   rF    s    rF  modec                 C   s   t | |d}t | |d}t | |d}|p|p|}|sd S | j  td |tjkrD|rFt| j|r:td d S t	dddd	d
 d S d S d S )NrB   build_optionsrC   zImplying --no-binary=:all: due to the presence of --build-option / --global-option / --install-option. Consider using --config-settings for more flexibility.z5Ignoring --install-option when building using PEP 517zv--install-option is deprecated because it forces pip to use the 'setup.py install' command which is itself deprecated.i^,  zto use --config-settingsz23.1)r:  r=  r;  r<  )
rD  format_controldisallow_binariesr   r   rF  rI  rE  rB   r(   )r@  rA  rL  has_install_optionshas_build_optionshas_global_optionslegacy_setup_py_options_presentr:   r:   rN   check_legacy_setup_py_options  s.   


rT  )mr8  loggingrT   r  r  r   r	  enumr   optparser   typingr   r   r   r   r   r	   r
   r   pip._vendor.packaging.markersr   "pip._vendor.packaging.requirementsr    pip._vendor.packaging.specifiersr   pip._vendor.packaging.utilsr   pip._vendor.packaging.versionr   r   r   pip._vendor.pyproject_hooksr   pip._internal.build_envr   r   pip._internal.exceptionsr   r   pip._internal.locationsr   pip._internal.metadatar   r   r   r   pip._internal.metadata.baser   pip._internal.models.direct_urlr   pip._internal.models.linkr   'pip._internal.operations.build.metadatar   0pip._internal.operations.build.metadata_editabler    .pip._internal.operations.build.metadata_legacyr   0pip._internal.operations.install.editable_legacyr!   r+  'pip._internal.operations.install.legacyr"   r/  &pip._internal.operations.install.wheelr#   pip._internal.pyprojectr$   r%   pip._internal.req.req_uninstallr&   pip._internal.utils.deprecationr'   r(   &pip._internal.utils.direct_url_helpersr)   r*   pip._internal.utils.hashesr+   pip._internal.utils.miscr,   r-   r.   r/   r0   r1   pip._internal.utils.packagingr3   pip._internal.utils.subprocessr4   pip._internal.utils.temp_dirr5   r6   pip._internal.utils.virtualenvr7   pip._internal.vcsr8   	getLoggerrv   r   r9   ro   r?  r   rD  rE  rF  rT  r:   r:   r:   rN   <module>   s   ( 
      	
	