a
    e0h                     @   s@  d dl m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	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 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. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZI d dlJmKZK eGrd dlLmMZMmNZNmOZOmPZPmQZQmRZRmSZS d dlTmUZU d d lVmWZW d d!lXmYZY d d"lmZZZ e[e\Z]d#d$ Z^G d%d& d&e_Z`d'd( ZadS ))    )absolute_importN)pkg_resourcessix)Requirement)canonicalize_name)Version)parse)Pep517HookCaller)NoOpBuildEnvironment)InstallationError)
get_scheme)Link)generate_metadata)install_editable)LegacyInstallFailure)install)install_wheel)load_pyproject_tomlmake_pyproject_path)UninstallPathSet)
deprecated)direct_url_from_link)Hashes)
indent_log)	ask_path_exists
backup_dirdisplay_pathdist_in_site_packagesdist_in_usersiteget_distributionget_installed_versionhide_urlredact_auth_from_url)get_metadata)TempDirectorytempdir_kinds)MYPY_CHECK_RUNNING)running_under_virtualenv)vcs)AnyDictIterableListOptionalSequenceUnion)Marker)SpecifierSet)Distribution)BuildEnvironmentc                 C   s   |  tj}tj|\}}t||}|drJtj}tj	|d }n.|dsXJ tj
}tj	|d dd }||||dS )zQReturn a pkg_resources.Distribution for the provided
    metadata directory.
    z	.egg-infor   z
.dist-info-)project_namemetadata)rstriposseppathsplitr   PathMetadataendswithr2   splitextDistInfoDistribution)metadata_directorydist_dirbase_dirdist_dir_namer6   dist_cls	dist_name rF   K/var/www/auris/lib/python3.9/site-packages/pip/_internal/req/req_install.py	_get_distF   s    
rH   c                   @   sF  e Zd ZdZdFddZdd Zd	d
 Zdd Zedd Z	edd Z
edd Zedd ZdGddZedd ZdHddZdd Zdd Zd d! Zd"d# Zd$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zd.d/ Zd0d1 Zd2d3 Zed4d5 Zd6d7 Zd8d9 ZdId:d;ZdJd<d=Z dKd>d?Z!d@dA Z"dBdC Z#dLdDdEZ$dS )M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.
    FNrF   c                 C   s  |d u st |tsJ ||| _|| _|| _|| _d | _d | _| jrj|sLJ |jrjt	j
t	j
|j| _|d u r|r|jrt|j}| | _| _d| _d | _| jr| jjr| jj| _|r|| _n |rd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 rF   )r   
safe_extra.0extrarF   rF   rG   	<setcomp>   s   z.InstallRequirement.__init__.<locals>.<setcomp>)*
isinstancer   req
comes_from
constrainteditablelegacy_install_reason
source_diris_filer8   r:   normpathabspath	file_pathurlr   linkoriginal_linkoriginal_link_is_in_wheel_cachelocal_file_pathextrassetmarkermarkerssatisfied_byshould_reinstall_temp_build_dirinstall_succeededinstall_optionsglobal_optionshash_optionsprepareduser_suppliedisolatedr
   	build_envr@   pyproject_requiresrequirements_to_checkpep517_backend
use_pep517needs_more_preparation)selfrP   rQ   rS   r[   rb   rq   rl   rg   rh   ri   rR   r_   rk   rF   rF   rG   __init__h   s^    


zInstallRequirement.__init__c                 C   s   | j r.t| j }| jrF|dt| jj7 }n| jrBt| jj}nd}| jd urf|dt| jj7 }| j	rt
| j	tjr| j	}n
| j	 }|r|d|7 }|S )Nz from {}z<InstallRequirement>z in {}z
 (from {}))rP   strr[   formatr"   rZ   rc   r   locationrQ   rO   r   string_types	from_pathrs   srQ   rF   rF   rG   __str__   s     


zInstallRequirement.__str__c                 C   s   d | jjt| | jS )Nz<{} object: {} editable={!r}>)rv   	__class____name__ru   rS   rs   rF   rF   rG   __repr__   s    zInstallRequirement.__repr__c                    s>   t |  t } fddt|D }dj| jjd|dS )z>An un-tested helper for getting state, for debugging.
        c                 3   s   | ]}d  | | V  qdS )z{}={!r}N)rv   )rL   attr
attributesrF   rG   	<genexpr>   s   z2InstallRequirement.format_debug.<locals>.<genexpr>z<{name} object: {{{state}}}>z, )namestate)varssortedrv   r}   r~   join)rs   namesr   rF   r   rG   format_debug   s    
zInstallRequirement.format_debugc                 C   s"   | j d u rd S tt| j jS N)rP   r   
ensure_strr   	safe_namer   r   rF   rF   rG   r      s    
zInstallRequirement.namec                 C   s   | j jS r   )rP   	specifierr   rF   rF   rG   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)rs   
specifiersrF   rF   rG   	is_pinned  s    zInstallRequirement.is_pinnedc                 C   s
   t | jS r   )r    r   r   rF   rF   rG   installed_version  s    z$InstallRequirement.installed_versionc                    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 )rM   N)rb   evaluaterK   r   rF   rG   r   "  s   z3InstallRequirement.match_markers.<locals>.<genexpr>T)rb   any)rs   extras_requestedrF   r   rG   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.

        )boolri   r   rF   rF   rG   has_hash_options(  s    	z#InstallRequirement.has_hash_optionsTc                 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()

        )	ri   copyr[   r\   hash
setdefault	hash_nameappendr   )rs   trust_internetgood_hashesr[   rF   rF   rG   hashes3  s
    

zInstallRequirement.hashesc                 C   sR   | j du rdS t| j }| jrNt| jtjr4| j}n
| j }|rN|d| 7 }|S )z@Format a nice indicator to show where this "comes from"
        Nz->)rP   ru   rQ   rO   r   rx   ry   rz   rF   rF   rG   ry   I  s    


zInstallRequirement.from_pathc                 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}|rld|t	
 j}tj|std| t| tj||}|rd nd}t||tjddjS )NT)kindglobally_managedz{}_{}zCreating directory %sF)r:   deleter   r   )re   r:   rP   r$   r%   	REQ_BUILDr   r   rv   uuiduuid4hexr8   existsloggerdebugmakedirsr   )rs   	build_dir
autodeleteparallel_buildsdir_nameactual_build_dir
delete_argrF   rF   rG   ensure_build_locationY  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 )z3Set requirement after generating metadata.
        Nr   r   r   r   Name)rP   r6   rU   rO   parse_versionr   r   r   )rs   oprF   rF   rG   _set_requirement  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   r6   rP   r   r   warningr   )rs   metadata_namerF   rF   rG   warn_on_mismatching_name  s    
z+InstallRequirement.warn_on_mismatching_namec                 C   s   | j du rdS t| j j}|s"dS |j}|duo@| j jj|dd}|sd| _|rt|r`d| _qt	 rt
|rtd|j|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)prereleaseszVWill not install to the user site because it will lack sys.path precedence to {} in {})rP   r   r   versionr   containsrc   r   rd   r'   r   r   rv   r5   rw   rS   )rs   use_user_siteexisting_distexisting_versionversion_compatiblerF   rF   rG   check_if_exists  s6    
z"InstallRequirement.check_if_existsc                 C   s   | j s
dS | j jS )NF)r[   is_wheelr   rF   rF   rG   r     s    zInstallRequirement.is_wheelc                 C   s   t j| j| jr| jjpdS )Nr   )r8   r:   r   rU   r[   subdirectory_fragmentr   rF   rF   rG   unpacked_source_directory  s    z,InstallRequirement.unpacked_source_directoryc                 C   sH   | j sJ d| tj| jd}tjrDt|tj	rD|
t }|S )NNo source dir for {}zsetup.py)rU   rv   r8   r:   r   r   r   PY2rO   	text_typeencodesysgetfilesystemencoding)rs   setup_pyrF   rF   rG   setup_py_path  s
    z InstallRequirement.setup_py_pathc                 C   s   | j sJ d| t| jS )Nr   )rU   rv   r   r   r   rF   rF   rG   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   rq   r   r   ru   ro   rn   r	   r   rp   )rs   pyproject_toml_datarequiresbackendcheckr   rF   rF   rG   r     s     	z&InstallRequirement.load_pyproject_tomlc                 C   sV   | j s8| jsJ t| j| j| j| j| jp2d| jdS | j	dusFJ t
| j| j	dS )zKInvokes metadata generator functions, with the required arguments.
        zfrom {})rm   r   rU   rl   detailsN)rm   r   )rq   r   generate_metadata_legacyrm   r   rl   r   rv   r[   rp   r   r   rF   rF   rG   _generate_metadata  s    
z%InstallRequirement._generate_metadatac                 C   s^   | j s
J t  |  | _W d   n1 s00    Y  | jsJ|   n|   |   dS )zEnsure that project metadata is available.

        Under PEP 517, call the backend hook to prepare the metadata.
        Under legacy processing, call setup.py egg-info.
        N)rU   r   r   r@   r   r   r   assert_source_matches_versionr   rF   rF   rG   prepare_metadata)  s    
(
z#InstallRequirement.prepare_metadatac                 C   s   t | dst|  | _| jS )N	_metadata)hasattrr#   get_distr   r   rF   rF   rG   r6   =  s    
zInstallRequirement.metadatac                 C   s
   t | jS r   )rH   r@   r   rF   rF   rG   r   E  s    zInstallRequirement.get_distc                 C   sR   | j s
J | jd }| jjr8|| jjvr8td| | ntdt| j ||  d S )Nr   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)rU   r6   rP   r   r   r   r   r   )rs   r   rF   rF   rG   r   I  s    

z0InstallRequirement.assert_source_matches_versionc                 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   )rU   r   )rs   
parent_dirr   r   rF   rF   rG   ensure_has_source_dir\  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 d| j jv s^J djf i t | j j	dd\}}t
|}|r| j jsd| j j}d }| j jdrd}t||d	d
d t| j j}|r|j| j|d n|j| j|d ndsJ d| j |d S )Nz>Cannot update repository at %s; repository location is unknownfile+zbad url: {self.link.url!r}r   z5This form of VCS requirement is being deprecated: {}.zgit+git@zmgit+https://git@example.com/..., git+ssh://git@example.com/..., or the insecure git+git://git@example.com/...21.0i  )gone_inissue)rZ   r   z+Unexpected version control type (in {}): {})r[   r   r   rU   rS   schemerZ   rv   localsr;   r(   get_backendis_vcs
startswithr   r!   obtainexport)rs   r   vc_typerZ   vcs_backendreasonreplacement
hidden_urlrF   rF   rG   update_editablet  sF    


z"InstallRequirement.update_editablec                 C   sR   | 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)	rP   r   r   r   r   infor   	from_distremove)rs   auto_confirmverbosedistuninstalled_pathsetrF   rF   rG   	uninstall  s    

zInstallRequirement.uninstallc                 C   s.   dd }t j||}|||}| jd | S )Nc                 S   sP   |  |tjj s(J djf i t | t|d d  } | tjjd} | S )Nz2name {name!r} doesn't start with prefix {prefix!r}r   /)r   r8   r:   r9   rv   r   r   replace)r   prefixrF   rF   rG   _clean_zip_name  s    z=InstallRequirement._get_archive_name.<locals>._clean_zip_namer   )r8   r:   r   r   )rs   r:   	parentdirrootdirr  r   rF   rF   rG   _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|rtdt	|d}|dkrjd}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|	|}||| q`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   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)rU   rv   r   r6   r8   r:   r   r   r   r   r   r   r   r   shutilmover   exitzipfileZipFileZIP_DEFLATEDnormcaserX   r   walkr  ZipInfoexternal_attrwritestrwriter   )rs   r   create_archivearchive_namearchive_pathresponse	dest_file
zip_outputdirdirpathdirnames	filenamesdirnamedir_arcnamezipdirfilenamefile_arcnamerF   rF   rG   archive  sh    


4zInstallRequirement.archivec	                 C   s  t | j|||| j|d}	|d ur$|ng }| jr^t|||||| j| j| j| j| jd
 d| _d S | j	r| j
snJ d }
| jrt| j| j| j}
t| j| j
|	t| j|||
| jd d| _d S t|| j }t|| j }z8t||||||||	| j| j| j| j| jt| jd}W nR tyD } zd| _tj|j  W Y d }~n$d }~0  ty^   d| _ Y n0 || _|r| jdkrtd| jd	d
dd d S )N)userhomerootrl   r  )r  r)  r   r   r   rl   rm   r   T)r   req_description	pycompilewarn_script_location
direct_url	requested)rg   rh   r*  r)  r  r   r,  r   r   rl   req_namerm   r   r+  Fi   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 abover   r   r   r   r   )r   r   rl   rS   install_editable_legacyr   rm   r   rf   r   r^   r\   r   rU   r]   r   ru   rP   rk   listrh   rg   install_legacyr   r   reraiseparent	ExceptionrT   r   rv   )rs   rg   rh   r*  r)  r  r-  r   r,  r   r.  successexcrF   rF   rG   r   	  s    	

	
 zInstallRequirement.install)FNNNFNNNFrF   F)N)T)FF)T)FF)NNNNTFT)%r~   
__module____qualname____doc__rt   r|   r   r   propertyr   r   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   r   r   r   r  r'  r   rF   rF   rF   rG   rI   a   s~   
           
m








*-




  

,
B       rI   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 constraintsz$Links 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 requirement.i   r1  )r   r[   r_   r   )rP   problemrF   rF   rG   check_invalid_constraint_typev  s    r?  )b
__future__r   loggingr8   r  r   r   r  pip._vendorr   r   "pip._vendor.packaging.requirementsr   pip._vendor.packaging.utilsr   Zpip._vendor.packaging.versionr   r   r   pip._vendor.pep517.wrappersr	   pip._internal.build_envr
   pip._internal.exceptionsr   pip._internal.locationsr   pip._internal.models.linkr   'pip._internal.operations.build.metadatar   .pip._internal.operations.build.metadata_legacyr   0pip._internal.operations.install.editable_legacyr   r2  'pip._internal.operations.install.legacyr   r   r4  &pip._internal.operations.install.wheelr   pip._internal.pyprojectr   r   pip._internal.req.req_uninstallr   pip._internal.utils.deprecationr   &pip._internal.utils.direct_url_helpersr   pip._internal.utils.hashesr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   r   r   r   r   r    r!   r"   pip._internal.utils.packagingr#   pip._internal.utils.temp_dirr$   r%   pip._internal.utils.typingr&   pip._internal.utils.virtualenvr'   pip._internal.vcsr(   typingr)   r*   r+   r,   r-   r.   r/   Zpip._vendor.packaging.markersr0   Z pip._vendor.packaging.specifiersr1   Zpip._vendor.pkg_resourcesr2   r3   	getLoggerr~   r   rH   objectrI   r?  rF   rF   rF   rG   <module>   sd   ,$
      