a
    0foM                     @   s  d dl Z d dl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mZ d dlmZ d dlmZmZmZmZ d dlmZ d dlmZmZ d d	lm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(m)Z)m*Z* erddl+m,Z, e -e.Z/e	d Z0e
edZ1e(ee0 dddZ2ee"e"dddZ3ee"e"dddZ4ee"e"dddZ5G dd de(Z6G d d! d!e6Z7G d"d# d#e6Z8G d$d% d%e(Z9G d&d' d'e(Z:G d(d) d)e(Z;dS )*    N)TYPE_CHECKINGAny	FrozenSetIterableOptionalTupleUnioncast)InvalidRequirement)NormalizedNamecanonicalize_name)Version)	HashErrorInstallationSubprocessErrorMetadataInconsistentMetadataInvalid)BaseDistribution)Linklinks_equivalent)Wheel)install_req_from_editableinstall_req_from_line)InstallRequirement)direct_url_from_link)normalize_version_info   )	CandidateRequirementformat_name)Factory)AlreadyInstalledCandidateEditableCandidateLinkCandidatez<Python from Requires-Python>)	candidatereturnc                 C   s   t ttf}t| |r| S dS )z%The runtime version of BaseCandidate.N)r    r!   r"   
isinstance)r#   base_candidate_classes r'   g/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.pyas_base_candidate+   s    
r)   )linktemplater$   c                 C   sj   |j rJ d|jr t|j}n| j}t||j|j|j|j|j	|j
|j|jd	}|j|_| |_|j|_|S )Nztemplate is editableuser_supplied
comes_from
use_pep517isolated
constraintglobal_optionshash_optionsconfig_settings)editablereqstrurlr   r-   r.   r/   r0   r1   r2   r3   r4   original_linkr*   extras)r*   r+   lineireqr'   r'   r(   make_install_req_from_link7   s&    r=   c                 C   sJ   |j sJ dt| j|j|j|j|j|j|j|j	|j
|jd
}|j|_|S )Nztemplate not editable)	r-   r.   r/   r0   r1   permit_editable_wheelsr2   r3   r4   )r5   r   r8   r-   r.   r/   r0   r1   r>   r2   r3   r4   r:   )r*   r+   r<   r'   r'   r(   make_install_req_from_editableP   s    r?   )distr+   r$   c                 C   st   |j rt|j }n.|jr.| j d|jj }n| j d| j }t||j|j|j	|j
|j|j|j|jd	}| |_|S )Nz @ z==r,   )r6   r7   r*   canonical_namer8   versionr   r-   r.   r/   r0   r1   r2   r3   r4   satisfied_by)r@   r+   r;   r<   r'   r'   r(   _make_install_req_from_distd   s$    rD   c                	   @   s,  e Zd ZU dZeed< dZd)eeed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dddZee	e d	ddZee
d	ddZeed	ddZeed	ddZed	ddZed	ddZeddd d!Zed	d"d#Zeee	e  d$d%d&Z e	e d	d'd(Z!dS )*"_InstallRequirementBackedCandidatea  A candidate backed by an ``InstallRequirement``.

    This represents a package request with the target not being already
    in the environment, and needs to be fetched and installed. The backing
    ``InstallRequirement`` is responsible for most of the leg work; this
    class exposes appropriate information to the resolver.

    :param link: The link passed to the ``InstallRequirement``. The backing
        ``InstallRequirement`` will use this link to fetch the distribution.
    :param source_link: The link this candidate "originates" from. This is
        different from ``link`` when the link is found in the wheel cache.
        ``link`` would point to the wheel cache, while this points to the
        found remote link (e.g. from pypi.org).
    r@   FNr   )r*   source_linkr<   factorynamerB   r$   c                 C   s8   || _ || _|| _|| _|| _|| _|  | _d | _d S N)	_link_source_link_factory_ireq_name_version_preparer@   _hash)selfr*   rF   r<   rG   rH   rB   r'   r'   r(   __init__   s    	
z+_InstallRequirementBackedCandidate.__init__r$   c                 C   s   | j  d| j S )N rH   rB   rR   r'   r'   r(   __str__   s    z*_InstallRequirementBackedCandidate.__str__c                 C   s   | j j dt| jdS N())	__class____name__r7   rJ   rW   r'   r'   r(   __repr__   s    z+_InstallRequirementBackedCandidate.__repr__c                 C   s(   | j d ur| j S t| j| jf| _ | j S rI   )rQ   hashr\   rJ   rW   r'   r'   r(   __hash__   s    
z+_InstallRequirementBackedCandidate.__hash__otherr$   c                 C   s   t || jrt| j|jS dS NF)r%   r\   r   rJ   rR   rb   r'   r'   r(   __eq__   s    z)_InstallRequirementBackedCandidate.__eq__c                 C   s   | j S rI   )rK   rW   r'   r'   r(   rF      s    z._InstallRequirementBackedCandidate.source_linkc                 C   s   | j du r| jj| _ | j S ):The normalised name of the project the candidate refers toN)rN   r@   rA   rW   r'   r'   r(   project_name   s    

z/_InstallRequirementBackedCandidate.project_namec                 C   s   | j S rI   rg   rW   r'   r'   r(   rH      s    z'_InstallRequirementBackedCandidate.namec                 C   s   | j d u r| jj| _ | j S rI   rO   r@   rB   rW   r'   r'   r(   rB      s    

z*_InstallRequirementBackedCandidate.versionc                 C   s,   | j  d| j d| jjr | jjn| j dS )NrU   z (from r[   )rH   rB   rJ   is_file	file_pathrW   r'   r'   r(   format_for_error   s    z3_InstallRequirementBackedCandidate.format_for_errorc                 C   s   t dd S )NzOverride in subclass)NotImplementedErrorrW   r'   r'   r(   _prepare_distribution   s    z8_InstallRequirementBackedCandidate._prepare_distribution)r@   r$   c              
   C   s   | j dur*| j |jkr*t| jd| j |j| jdur\| j|jkr\t| jdt| jt|jzt|t|	  W n4 t
y } zt| jt|W Y d}~n
d}~0 0 dS )z:Check for consistency of project name and version of dist.NrH   rB   )rN   rA   r   rM   rO   rB   r7   listiter_dependenciesiter_provided_extrasr
   r   )rR   r@   er'   r'   r(   _check_metadata_consistency   s$    	z>_InstallRequirementBackedCandidate._check_metadata_consistencyc              
   C   st   z|   }W nX ty: } z| j|_ W Y d }~n4d }~0  tyd } zd|_ W Y d }~n
d }~0 0 | | |S )NzSee above for output.)rn   r   rM   r6   r   contextrs   )rR   r@   rr   excr'   r'   r(   rP      s    
z+_InstallRequirementBackedCandidate._preparewith_requiresr$   c                 c   sL   |r| j  nd}|D ]}| jt|| jE d H  q| j| j jV  d S Nr'   )r@   rp   rL   make_requirements_from_specr7   rM    make_requires_python_requirementrequires_python)rR   rw   requiresrr'   r'   r(   rp      s    z4_InstallRequirementBackedCandidate.iter_dependenciesc                 C   s   | j S rI   )rM   rW   r'   r'   r(   get_install_requirement   s    z:_InstallRequirementBackedCandidate.get_install_requirement)NN)"r]   
__module____qualname____doc__r   __annotations__is_installedr   r   r   r   r   rS   r7   rX   r^   intr`   r   boolre   propertyrF   rg   rH   rB   rl   rn   rs   rP   r   r   rp   r~   r'   r'   r'   r(   rE   |   s@   
  rE   c                       sH   e Zd ZdZd
eedee ee dd fddZ	e
ddd	Z  ZS )r"   FNr   r*   r+   rG   rH   rB   r$   c                    s4  |}| ||}|d ur,td|j |j}t||}|j|ksDJ |jjr|jjst|jj}	t	|	j
}
||
ksJ |d|
d|d urt|	j}||ksJ |d|d| |d ur|jjsJ |jjsJ |jr|j|ju r||_|jd ur|j|_nt||jd|_t j||||||d d S )NzUsing cached wheel link: %sz != z
 for wheelz for wheel )link_is_in_wheel_cacher*   rF   r<   rG   rH   rB   )get_wheel_cache_entryloggerdebugr*   r=   is_wheelrj   r   filenamer   rH   r   rB   
persistentr9   Zcached_wheel_source_linkorigindownload_infor   superrS   )rR   r*   r+   rG   rH   rB   rF   cache_entryr<   wheel
wheel_namewheel_versionr\   r'   r(   rS     sF    




zLinkCandidate.__init__rT   c                 C   s   | j j}|j| jddS )NT)parallel_builds)rL   preparerprepare_linked_requirementrM   )rR   r   r'   r'   r(   rn   8  s    z#LinkCandidate._prepare_distribution)NNr]   r   r   is_editabler   r   r   r   r   rS   r   rn   __classcell__r'   r'   r   r(   r"     s     1r"   c                       sH   e Zd ZdZd
eedee ee dd fddZ	e
ddd	Z  ZS )r!   TNr   r   c                    s"   t  j||t|||||d d S )Nr   )r   rS   r?   )rR   r*   r+   rG   rH   rB   r   r'   r(   rS   @  s    zEditableCandidate.__init__rT   c                 C   s   | j j| jS rI   )rL   r   prepare_editable_requirementrM   rW   r'   r'   r(   rn   Q  s    z'EditableCandidate._prepare_distribution)NNr   r'   r'   r   r(   r!   =  s     r!   c                   @   s   e Zd ZdZdZeedddddZeddd	Z	edd
dZ
eedddZedddZeedddZeedddZeedddZeedddZedddZeeee  dddZee dddZdS ) r    TNr   )r@   r+   rG   r$   c                 C   s6   || _ t||| _|| _d | _d}|j| j| d S )Nzalready satisfied)r@   rD   rM   rL   rO   r   prepare_installed_requirement)rR   r@   r+   rG   skip_reasonr'   r'   r(   rS   Y  s    z"AlreadyInstalledCandidate.__init__rT   c                 C   s
   t | jS rI   )r7   r@   rW   r'   r'   r(   rX   k  s    z!AlreadyInstalledCandidate.__str__c                 C   s   | j j d| jdS rY   )r\   r]   r@   rW   r'   r'   r(   r^   n  s    z"AlreadyInstalledCandidate.__repr__ra   c                 C   s&   t |tstS | j|jko$| j|jkS rI   )r%   r    NotImplementedrH   rB   rd   r'   r'   r(   re   q  s    
z AlreadyInstalledCandidate.__eq__c                 C   s   t | j| jfS rI   )r_   rH   rB   rW   r'   r'   r(   r`   v  s    z"AlreadyInstalledCandidate.__hash__c                 C   s   | j jS rI   )r@   rA   rW   r'   r'   r(   rg   y  s    z&AlreadyInstalledCandidate.project_namec                 C   s   | j S rI   rh   rW   r'   r'   r(   rH   }  s    zAlreadyInstalledCandidate.namec                 C   s   | j d u r| jj| _ | j S rI   ri   rW   r'   r'   r(   rB     s    

z!AlreadyInstalledCandidate.versionc                 C   s   | j jS rI   )r@   r5   rW   r'   r'   r(   r     s    z%AlreadyInstalledCandidate.is_editablec                 C   s   | j  d| j dS )NrU   z (Installed)rV   rW   r'   r'   r(   rl     s    z*AlreadyInstalledCandidate.format_for_errorrv   c                 c   s6   |sd S | j  D ]}| jt|| jE d H  qd S rI   )r@   rp   rL   ry   r7   rM   )rR   rw   r}   r'   r'   r(   rp     s    z+AlreadyInstalledCandidate.iter_dependenciesc                 C   s   d S rI   r'   rW   r'   r'   r(   r~     s    z1AlreadyInstalledCandidate.get_install_requirement)r]   r   r   r   rF   r   r   rS   r7   rX   r^   objectr   re   r   r`   r   r   rg   rH   r   rB   r   rl   r   r   r   rp   r~   r'   r'   r'   r(   r    U  s,   r    c                   @   s  e Zd ZdZdd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dddZeedddZeedddZeedddZedddZeedddZeedddZeee dddZeeee  dd d!Zee dd"d#ZdS )$ExtrasCandidatea  A candidate that has 'extras', indicating additional dependencies.

    Requirements can be for a project with dependencies, something like
    foo[extra].  The extras don't affect the project/version being installed
    directly, but indicate that we need additional dependencies. We model that
    by having an artificial ExtrasCandidate that wraps the "base" candidate.

    The ExtrasCandidate differs from the base in the following ways:

    1. It has a unique name, of the form foo[extra]. This causes the resolver
       to treat it as a separate node in the dependency graph.
    2. When we're getting the candidate's dependencies,
       a) We specify that we want the extra dependencies as well.
       b) We add a dependency on the base candidate.
          See below for why this is needed.
    3. We return None for the underlying InstallRequirement, as the base
       candidate will provide it, and we don't want to end up with duplicates.

    The dependency on the base candidate is needed so that the resolver can't
    decide that it should recommend foo[extra1] version 1.0 and foo[extra2]
    version 2.0. Having those candidates depend on foo=1.0 and foo=2.0
    respectively forces the resolver to recognise that this is a conflict.
    N)r.   )baser:   r.   r$   c                C   s4   || _ tdd |D | _|dur&|n| j j| _dS )a  
        :param comes_from: the InstallRequirement that led to this candidate if it
            differs from the base's InstallRequirement. This will often be the
            case in the sense that this candidate's requirement has the extras
            while the base's does not. Unlike the InstallRequirement backed
            candidates, this requirement is used solely for reporting purposes,
            it does not do any leg work.
        c                 s   s   | ]}t |V  qd S rI   )r   ).0rr   r'   r'   r(   	<genexpr>      z+ExtrasCandidate.__init__.<locals>.<genexpr>N)r   	frozensetr:   rM   _comes_from)rR   r   r:   r.   r'   r'   r(   rS     s    zExtrasCandidate.__init__rT   c                 C   s,   t | jdd\}}d|d| j|S )NrU   r   z	{}[{}] {},)r7   r   splitformatjoinr:   )rR   rH   restr'   r'   r(   rX     s    zExtrasCandidate.__str__c                 C   s   | j j d| jd| jdS )Nz(base=z	, extras=r[   )r\   r]   r   r:   rW   r'   r'   r(   r^     s    zExtrasCandidate.__repr__c                 C   s   t | j| jfS rI   )r_   r   r:   rW   r'   r'   r(   r`     s    zExtrasCandidate.__hash__ra   c                 C   s(   t || jr$| j|jko"| j|jkS dS rc   )r%   r\   r   r:   rd   r'   r'   r(   re     s    zExtrasCandidate.__eq__c                 C   s   | j jS rI   )r   rg   rW   r'   r'   r(   rg     s    zExtrasCandidate.project_namec                 C   s   t | jj| jS )rf   )r   r   rg   r:   rW   r'   r'   r(   rH     s    zExtrasCandidate.namec                 C   s   | j jS rI   )r   rB   rW   r'   r'   r(   rB     s    zExtrasCandidate.versionc                 C   s   d | j dt| jS )Nz{} [{}]z, )r   r   rl   r   sortedr:   rW   r'   r'   r(   rl     s    z ExtrasCandidate.format_for_errorc                 C   s   | j jS rI   )r   r   rW   r'   r'   r(   r     s    zExtrasCandidate.is_installedc                 C   s   | j jS rI   )r   r   rW   r'   r'   r(   r     s    zExtrasCandidate.is_editablec                 C   s   | j jS rI   )r   rF   rW   r'   r'   r(   rF     s    zExtrasCandidate.source_linkrv   c                 c   s   | j j}|| j V  |sd S | j| j j }| j| j j }t|D ]}t	
d| j j| j| qN| j j|D ]}|t|| j|E d H  qxd S )Nz%%s %s does not provide the extra '%s')r   rL   make_requirement_from_candidater:   intersectionr@   rq   
differencer   r   warningrH   rB   rp   ry   r7   r   )rR   rw   rG   valid_extrasinvalid_extrasextrar}   r'   r'   r(   rp     s&    z!ExtrasCandidate.iter_dependenciesc                 C   s   d S rI   r'   rW   r'   r'   r(   r~     s    z'ExtrasCandidate.get_install_requirement) r]   r   r   r   BaseCandidater   r7   r   r   rS   rX   r^   r   r`   r   r   re   r   r   rg   rH   r   rB   rl   r   r   r   rF   r   r   rp   r~   r'   r'   r'   r(   r     s6   r   c                   @   s   e Zd ZdZdZeeedf  ddddZe	ddd	Z
eedd
dZee	dddZeedddZe	dddZeeee  dddZee dddZdS )RequiresPythonCandidateFN.)py_version_infor$   c                 C   s>   |d urt |}ntjd d }tddd |D | _d S )N   .c                 s   s   | ]}t |V  qd S rI   )r7   )r   cr'   r'   r(   r     r   z3RequiresPythonCandidate.__init__.<locals>.<genexpr>)r   sysversion_infor   r   rO   )rR   r   r   r'   r'   r(   rS     s    
z RequiresPythonCandidate.__init__rT   c                 C   s   d| j  S NzPython rO   rW   r'   r'   r(   rX   #  s    zRequiresPythonCandidate.__str__c                 C   s   t S rI   REQUIRES_PYTHON_IDENTIFIERrW   r'   r'   r(   rg   &  s    z$RequiresPythonCandidate.project_namec                 C   s   t S rI   r   rW   r'   r'   r(   rH   *  s    zRequiresPythonCandidate.namec                 C   s   | j S rI   r   rW   r'   r'   r(   rB   .  s    zRequiresPythonCandidate.versionc                 C   s   d| j  S r   )rB   rW   r'   r'   r(   rl   2  s    z(RequiresPythonCandidate.format_for_errorrv   c                 C   s   dS rx   r'   )rR   rw   r'   r'   r(   rp   5  s    z)RequiresPythonCandidate.iter_dependenciesc                 C   s   d S rI   r'   rW   r'   r'   r(   r~   8  s    z/RequiresPythonCandidate.get_install_requirement)r]   r   r   r   rF   r   r   r   rS   r7   rX   r   r   rg   rH   r   rB   rl   r   r   r   rp   r   r~   r'   r'   r'   r(   r     s   r   )<loggingr   typingr   r   r   r   r   r   r   r	   "pip._vendor.packaging.requirementsr
   Zpip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   pip._internal.exceptionsr   r   r   r   pip._internal.metadatar   pip._internal.models.linkr   r   pip._internal.models.wheelr   pip._internal.req.constructorsr   r   Zpip._internal.req.req_installr   &pip._internal.utils.direct_url_helpersr   pip._internal.utils.miscr   r   r   r   r   rG   r   	getLoggerr]   r   r   r   r)   r=   r?   rD   rE   r"   r!   r    r   r   r'   r'   r'   r(   <module>   sL   (

 	9C|