a
    0f̋                     @   sr  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l@mAZAmBZB d dlCmDZD d dlEmFZF d dlGmHZH d dlImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ d dlRmSZS d dlTmUZU d dlVmWZWmXZX d dlYmZZZ d d l[m\Z\ d d!l]m^Z^ e_e`ZaG d"d# d#Zbebecd$d%d&Zdeeeb eceed'd(d)Zfeeeb dd*d+d,ZgdS )-    N)Values)Path)Any
CollectionDictIterableListOptionalSequenceUnion)Marker)Requirement)SpecifierSet)canonicalize_name)Version)parse)BuildBackendHookCaller)BuildEnvironmentNoOpBuildEnvironment)InstallationErrorPreviousBuildDirError)
get_scheme)BaseDistributionget_default_environmentget_directory_distributionget_wheel_distribution)FilesystemWheel)	DirectUrl)Link)generate_metadata)generate_editable_metadata)install_editable)install_wheel)load_pyproject_tomlmake_pyproject_path)UninstallPathSet)
deprecated)Hashes) ConfiguredBuildBackendHookCallerask_path_exists
backup_dirdisplay_pathhide_urlis_installable_dirredact_auth_from_requirementredact_auth_from_url)get_requirement)runner_with_spinner_message)TempDirectorytempdir_kinds)unpack_file)running_under_virtualenv)vcsc                   @   s0  e Zd ZdZd]ddddddddee eeed f  eee	 ee
 ee eeee  eeeee f  eeeeeee f f  eee eeddddZed	d
dZed	ddZed	ddZeee d	ddZejed	ddZeed	ddZeed	ddZeed	ddZd^eee  edddZeed	ddZd_eed d!d"Zee d	d#d$Z eeeed%d&d'Z!dd	d(d)Z"dd	d*d+Z#edd,d-d.Z$eed	d/d0Z%eed	d1d2Z&eed	d3d4Z'eed	d5d6Z(eed	d7d8Z)eed	d9d:Z*dd	d;d<Z+dd	d=d>Z,dd	d?d@Z-ee.d	dAdBZ/e0d	dCdDZ1dd	dEdFZ2d`eeeddGdHdIZ3e4ddJdKdLZ5dd	dMdNZ6dd	dOdPZ7daeeee8 dQdRdSZ9eeeedTdUdVZ:ee ddWdXdYZ;dbee<e  ee ee ee eeeddZd[d\Z=dS )c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 )global_optionshash_optionsconfig_settings
constraintextrasuser_suppliedpermit_editable_wheels)req
comes_fromeditablelinkmarkers
use_pep517isolatedr9   r:   r;   r<   r=   r>   r?   returnc                C   s  |d u st |tsJ ||| _|| _|| _|| _|| _d | _| jrj|sLJ |jrjt	j
t	j
|j| _|d u r|r|jrt|j}| | _| _d | _d | _d | _| jr| jjr| jj| _|r|| _n|r|j| _nt | _|d u r|r|j}|| _d | _d| _d | _d | _|r|ng | _|	r(|	ni | _|
| _d| _ || _!|| _"t# | _$d | _%d | _&g | _'d | _(|| _)| jr| j)du rt*+d|  d| _)d| _,d | _-d S )NFzG--no-use-pep517 ignored for %s because --config-settings are specified.T).
isinstancer   r@   rA   r<   rB   r?   
source_diris_fileospathnormpathabspath	file_pathurlr   rC   original_linkcached_wheel_source_linkdownload_infolocal_file_pathr=   setmarkerrD   satisfied_byshould_reinstall_temp_build_dirinstall_succeededr9   r:   r;   preparedr>   rF   r   	build_envmetadata_directorypyproject_requiresrequirements_to_checkpep517_backendrE   loggerwarningneeds_more_preparation_archive_source)selfr@   rA   rB   rC   rD   rE   rF   r9   r:   r;   r<   r=   r>   r?   r8   r8   V/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/req/req_install.py__init__H   sh    


zInstallRequirement.__init__)rG   c                 C   s   | j r.t| j }| jrF|dt| jj 7 }n| jrBt| jj}nd}| jd ur|| jjd urjt| jj}nd}|d| 7 }| jrt	| jt
r| j}n
| j }|r|d| d7 }|S )Nz from z<InstallRequirement>z<memory> in z (from ))r@   r.   rC   r/   rP   rW   locationr+   rA   rH   str	from_path)re   srj   rA   r8   r8   rf   __str__   s&    


zInstallRequirement.__str__c                 C   s"   d| j j dt|  d| jdS )N<z	 object: z
 editable=>)	__class____name__rk   rB   re   r8   r8   rf   __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 )=Nr8   ).0attr
attributesr8   rf   	<genexpr>       z2InstallRequirement.format_debug.<locals>.<genexpr>z<{name} object: {{{state}}}>z, )namestate)varssortedformatrq   rr   join)re   namesr}   r8   rx   rf   format_debug   s    zInstallRequirement.format_debugc                 C   s   | j d u rd S | j jS N)r@   r|   rs   r8   r8   rf   r|      s    
zInstallRequirement.namec              	   C   s   | j s
dS | jsJ | j` td}| j|, d| j v W  d    W  d    S 1 sb0    Y  W d    n1 s0    Y  d S )NFz1Checking if build backend supports build_editablebuild_editable)rE   r`   r\   r1   subprocess_runner_supported_features)re   runnerr8   r8   rf   supports_pyproject_editable   s    
z.InstallRequirement.supports_pyproject_editablec                 C   s   | j d usJ | j jS r   )r@   	specifierrs   r8   r8   rf   r     s    zInstallRequirement.specifierc                 C   s
   | j duS )z7Whether this requirement was specified as a direct URL.N)rQ   rs   r8   r8   rf   	is_direct	  s    zInstallRequirement.is_directc                 C   s4   | j dusJ | j j}t|dko2t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.
        N   >   =====)r@   r   lennextiteroperator)re   
specifiersr8   r8   rf   	is_pinned  s    zInstallRequirement.is_pinned)extras_requestedrG   c                    s0   |sd} j d ur(t fdd|D S dS d S )N) c                 3   s   | ]} j d |iV  qdS )extraN)rD   evaluate)rv   r   rs   r8   rf   rz     s   z3InstallRequirement.match_markers.<locals>.<genexpr>T)rD   any)re   r   r8   rs   rf   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.

        )boolr:   rs   r8   r8   rf   has_hash_options$  s    z#InstallRequirement.has_hash_optionsT)trust_internetrG   c                 C   sd   | j  }|r| j}n| jr*| jr*| j}nd}|r\|jr\|jdusFJ ||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()

        N)r:   copyrC   r   r>   rQ   hash	hash_name
setdefaultappendr'   )re   r   good_hashesrC   r8   r8   rf   hashes.  s    

zInstallRequirement.hashesc                 C   sP   | j du rdS t| j }| jrLt| jtr2| j}n
| j }|rL|d| 7 }|S )z8Format a nice indicator to show where this "comes from" Nz->)r@   rk   rA   rH   rl   )re   rm   rA   r8   r8   rf   rl   I  s    


zInstallRequirement.from_path)	build_dir
autodeleteparallel_buildsrG   c                 C   s   |d usJ | j d ur*| j js"J | j jS | jd u rLttjdd| _ | j jS t| jj}|rp| dt	 j
 }tj|std| t| tj||}|rd nd}t||tjddjS )NT)kindglobally_managed_zCreating directory %sF)rL   deleter   r   )rY   rL   r@   r2   r3   	REQ_BUILDr   r|   uuiduuid4hexrK   existsra   debugmakedirsr   )re   r   r   r   dir_nameactual_build_dir
delete_argr8   r8   rf   ensure_build_locationX  s.    


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rDd}nd}td| jd || jd g| _ dS )z*Set requirement after generating metadata.Nr   r   r   r   Name)r@   metadatarI   rH   parse_versionr   r0   r   )re   opr8   r8   rf   _set_requirement  s    z#InstallRequirement._set_requirementc                 C   sR   | j d usJ t| jd }t| j j|kr0d 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|   ra   rb   r0   )re   metadata_namer8   r8   rf   warn_on_mismatching_name  s    z+InstallRequirement.warn_on_mismatching_name)use_user_siterG   c                 C   s   | j du rdS t | j j}|s&dS | j jj|jdd}|sd| _|r||jrVd| _	qt
 r|jrtd|j d|j qd| _	n| jrd| _	d| _n|| _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 rh   )r@   r   get_distributionr|   r   containsversionrW   in_usersiterX   r5   in_site_packagesr   raw_namerj   rB   )re   r   existing_distversion_compatibler8   r8   rf   check_if_exists  s6    
z"InstallRequirement.check_if_existsc                 C   s   | j s
dS | j jS )NF)rC   is_wheelrs   r8   r8   rf   r     s    zInstallRequirement.is_wheelc                 C   s
   | j d uS r   )rR   rs   r8   r8   rf   is_wheel_from_cache  s    z&InstallRequirement.is_wheel_from_cachec                 C   s2   | j sJ d|  tj| j | jr,| jjp.dS )NNo source dir for r   )rI   rK   rL   r   rC   subdirectory_fragmentrs   r8   r8   rf   unpacked_source_directory  s    z,InstallRequirement.unpacked_source_directoryc                 C   s(   | j sJ d|  tj| jd}|S )Nr   zsetup.pyrI   rK   rL   r   r   )re   setup_pyr8   r8   rf   setup_py_path  s    z InstallRequirement.setup_py_pathc                 C   s(   | j sJ d|  tj| jd}|S )Nr   z	setup.cfgr   )re   	setup_cfgr8   r8   rf   setup_cfg_path  s    z!InstallRequirement.setup_cfg_pathc                 C   s   | j sJ d|  t| jS )Nr   )rI   r$   r   rs   r8   r8   rf   pyproject_toml_path  s    z&InstallRequirement.pyproject_toml_pathc                 C   sj   t | j| j| jt| }|du r4| jr*J 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#   rE   r   r   rk   r;   r_   r^   r(   r   r`   )re   pyproject_toml_datarequiresbackendcheckr   r8   r8   rf   r#     s"    
z&InstallRequirement.load_pyproject_tomlc                 C   sB   | j r>| jr>| js>tj| js>tj| js>td|  d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)	rB   rE   r   rK   rL   isfiler   r   r   rs   r8   r8   rf   isolated_editable_sanity_check  s    
z1InstallRequirement.isolated_editable_sanity_checkc                 C   s   | j sJ d|  | jp$d| j }| jrx| jdus:J | jrb| jrb| jrbt| j	| j|d| _
qt| j	| j|d| _
nt| j	| j| j| j|d| _
| js|   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.
        r   zfrom N)r\   r   details)r\   r   rI   rF   r   )rI   r|   rC   rE   r`   rB   r?   r   r    r\   r]   r   generate_metadata_legacyr   r   rF   r   r   assert_source_matches_version)re   r   r8   r8   rf   prepare_metadata)  s>    

	
z#InstallRequirement.prepare_metadatac                 C   s   t | ds|  j| _| jS )N	_metadata)hasattrget_distr   r   rs   r8   r8   rf   r   U  s    
zInstallRequirement.metadatac                 C   sV   | j rt| j S | jrB| jrB| jd us*J tt| jt| jjS t	d|  dd S )NzInstallRequirement zC has no metadata directory and no wheel: can't make a distribution.)
r]   r   rT   r   r@   r   r   r   r|   AssertionErrorrs   r8   r8   rf   r   \  s    


zInstallRequirement.get_distc                 C   sb   | j sJ d|  | jd }| jrH| jjrH|| jjvrHtd| | ntdt| j ||  d S )Nr   r   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)rI   r   r@   r   ra   rb   r   r+   )re   r   r8   r8   rf   r   j  s    
z0InstallRequirement.assert_source_matches_version)
parent_dirr   r   rG   c                 C   s    | j du r| j|||d| _ 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   )rI   r   )re   r   r   r   r8   r8   rf   ensure_has_source_dir|  s    
z(InstallRequirement.ensure_has_source_dir)archive_sourcerG   c                 C   s   | j d u sJ || _ d S r   )rd   )re   r   r8   r8   rf   needs_unpacked_archive  s    z)InstallRequirement.needs_unpacked_archivec                 C   sR   | j dusJ | jdur,tt| j| j  n"t| j rNtd|  d| j  ddS )z6Ensure the source directory has not yet been built in.Nz%pip can't proceed with requirements 'z)' due to a pre-existing build directory (z). 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.)rI   rd   r4   rk   r-   r   rs   r8   r8   rf   ensure_pristine_source_checkout  s    

z2InstallRequirement.ensure_pristine_source_checkoutc                 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}|s`J 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   )rP   	verbosity)rC   ra   r   rI   rB   schemer6   get_backend_for_schemerP   r,   obtain)re   vcs_backend
hidden_urlr8   r8   rf   update_editable  s    

z"InstallRequirement.update_editable)auto_confirmverboserG   c                 C   sV   | j s
J t | j j}|s0t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|   ra   rb   infor%   	from_distremove)re   r   r   distuninstalled_pathsetr8   r8   rf   	uninstall  s    

zInstallRequirement.uninstall)rL   	parentdirrootdirrG   c                 C   sH   t t t ddd}| jd us J tj||}|||}| jjd | S )N)r|   prefixrG   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   /)
startswithrK   rL   sepr   replace)r|   r   r8   r8   rf   _clean_zip_name  s    
z=InstallRequirement._get_archive_name.<locals>._clean_zip_namer   )rk   r@   rK   rL   r   r|   )re   rL   r   r   r   r|   r8   r8   rf   _get_archive_name  s
    
z$InstallRequirement._get_archive_name)r   rG   c                 C   s  | j s
J |du rdS d}d| j| jd }tj||}tj|rtdt	| dd}|dkrld	}nj|d
krt
dt	| t| nF|dkrt|}t
dt	|t	| t|| n|dkrtd |sdS tj|d
tjdd}| tjtj| j}t|D ]~\}	}
}|
D ]6}| j||	|d}t|d }d|_||d q&|D ]0}| j||	|d}tj|	|}||| qbqW d   n1 s0    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   z	The file z- 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)rI   r   r|   r   rK   rL   r   r   r)   r+   ra   rb   r   r*   shutilmovesysexitzipfileZipFileZIP_DEFLATEDnormcaserN   r   walkr   ZipInfoexternal_attrwritestrwriter   )re   r   create_archivearchive_namearchive_pathresponse	dest_file
zip_outputdirdirpathdirnames	filenamesdirnamedir_arcnamezipdirfilenamefile_arcnamer8   r8   rf   archive  sn    

4zInstallRequirement.archive)r9   roothomer   warn_script_locationr   	pycompilerG   c           	      C   s   | j d usJ t| j j|||| j|d}| jr| jstd|  ddddd | jr^t	d|  t
|d url|ng |||| j j| j| j| j| jd		 d
| _d S | jsJ | jsJ t| j j| j|t| j ||| jr| jnd | jd d
| _d S )N)userr%  r$  rF   r   zLegacy editable install of z" (setup.py develop) is deprecated.zto add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information25.0i,  reasonreplacementgone_inissuez--config-settings ignored for legacy editable install of %s. Consider upgrading to a version of setuptools that supports PEP 660 (>= 64).)	r9   r   r%  r   r|   r   rF   r\   r   T)r   req_descriptionr'  r&  
direct_url	requested)r@   r   r|   rF   rB   r   r&   r;   ra   rb   install_editable_legacyr   r\   r   rZ   rT   r"   rk   r   rS   r>   )	re   r9   r$  r%  r   r&  r   r'  r   r8   r8   rf   install'  s^    
	



zInstallRequirement.install)FNNNF)N)T)FF)FF)NNNNTFT)>rr   
__module____qualname____doc__r	   r   r   rk   r   r   r   r   r   r   rg   rn   rt   r   propertyr|   	functoolscached_propertyr   r   r   r   r   r   r   r   r'   r   rl   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
   r3  r8   r8   r8   rf   r7   A   s   
     

 		+&,   E       
r7   )r@   rG   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   r*  )r|   rB   r=   r&   )r@   problemr8   r8   rf   check_invalid_constraint_typep  s    r;  )optionsreqsoptionrG   c                 C   s0   t | |d rdS |D ]}t ||d r dS qdS )NTF)getattr)r<  r=  r>  r@   r8   r8   rf   _has_option  s    r@  )r<  r=  rG   c                 C   sH   t | |d}t | |d}|s |rDtddddd td | j  d S )	Nbuild_optionsr9   z2--build-option and --global-option are deprecated.iS.  zto use --config-settingsr)  )r+  r.  r,  r-  zTImplying --no-binary=:all: due to the presence of --build-option / --global-option. )r@  r&   ra   rb   format_controldisallow_binaries)r<  r=  has_build_optionshas_global_optionsr8   r8   rf   check_legacy_setup_py_options  s    rF  )hr8  loggingrK   r  r	  r   r  optparser   pathlibr   typingr   r   r   r   r   r	   r
   r   Zpip._vendor.packaging.markersr   "pip._vendor.packaging.requirementsr   Z pip._vendor.packaging.specifiersr   Zpip._vendor.packaging.utilsr   Z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   Z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!   r2  &pip._internal.operations.install.wheelr"   pip._internal.pyprojectr#   r$   pip._internal.req.req_uninstallr%   pip._internal.utils.deprecationr&   pip._internal.utils.hashesr'   pip._internal.utils.miscr(   r)   r*   r+   r,   r-   r.   r/   pip._internal.utils.packagingr0   pip._internal.utils.subprocessr1   pip._internal.utils.temp_dirr2   r3   pip._internal.utils.unpackingr4   pip._internal.utils.virtualenvr5   pip._internal.vcsr6   	getLoggerrr   ra   r7   rk   r;  r   r@  rF  r8   r8   r8   rf   <module>   sj   ((

      5
