o
    a+)hl                     @   s  d dl Z 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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mZ d dlmZ d dlmZmZ d dl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, d dl-m.Z. d dl/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= ddl>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJ ddlKmLZLmMZM ddlNmOZOmPZPmQZQmRZR erd dlmSZS G dd deSZTeUeVZWedZXee*eXf ZYG dd deZZG d d! d!Z[dS )"    N)TYPE_CHECKINGDict	FrozenSetIterableIteratorListMapping
NamedTupleOptionalSequenceSetTupleTypeVarcast)InvalidRequirement)SpecifierSet)NormalizedNamecanonicalize_name)ResolutionImpossible)
CacheEntry
WheelCache)DistributionNotFoundInstallationErrorMetadataInconsistentUnsupportedPythonVersionUnsupportedWheel)PackageFinder)BaseDistributionget_default_environment)Link)Wheel)RequirementPreparer)install_req_from_link_and_ireq)InstallRequirementcheck_invalid_constraint_type)InstallRequirementProvider)get_supported)Hashes)get_requirement)running_under_virtualenv   )	CandidateCandidateVersion
ConstraintRequirement)AlreadyInstalledCandidateBaseCandidateEditableCandidateExtrasCandidateLinkCandidateRequiresPythonCandidateas_base_candidate)FoundCandidatesIndexCandidateInfo)ExplicitRequirementRequiresPythonRequirementSpecifierRequirementUnsatisfiableRequirement)Protocolc                   @   s   e Zd ZU eed< eed< dS )ConflictCauserequirementparentN)__name__
__module____qualname__r9   __annotations__r+    rD   rD   jC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_internal/resolution/resolvelib/factory.pyr=   G   s   
 r=   Cc                   @   s:   e Zd ZU ee ed< eeef ed< eee	f ed< dS )CollectedRootRequirementsrequirementsconstraintsuser_requestedN)
r@   rA   rB   r   r.   rC   r   strr-   intrD   rD   rD   rE   rG   R   s   
 rG   c                   @   s  e Zd Z	dSdedededee dededed	ed
ee	e
df  ddfddZedefddZdeddfddZdedee defddZdedee dedefddZdedee dedee dee dee fddZd ee d!ed"ed#ed$ee
 de e fd%d&Z!d'e e" dee de#e fd(d)Z$d*ed+e%dede#e fd,d-Z&d*ed.e'ee e" f d/e'ee#e f d+e%d#ede e fd0d1Z(d2ed3e e dee" fd4d5Z)d6e*e de+fd7d8Z,d9ede-fd:d;Z.	<dTd!ed=ee d3e e dee" fd>d?Z/d!edee" fd@dAZ0dedee dee1 fdBdCZ2d9edee fdDdEZ3dFedG de4fdHdIZ5dJe"dKee de6fdLdMZ7dNdOdPe8ee%f de9fdQdRZ:dS )UFactoryNfinderpreparermake_install_reqwheel_cacheuse_user_siteforce_reinstallignore_installedignore_requires_pythonpy_version_info.returnc
                 C   s   || _ || _|| _t|	| _|| _|| _|| _|| _i | _	i | _
i | _i | _i | _|s<t }
dd |
jddD | _d S i | _d S )Nc                 S   s   i | ]}|j |qS rD   )canonical_name).0distrD   rD   rE   
<dictcomp>x   s    z$Factory.__init__.<locals>.<dictcomp>F)
local_only)_finderrO   _wheel_cacher4   _python_candidate_make_install_req_from_spec_use_user_site_force_reinstall_ignore_requires_python_build_failures_link_candidate_cache_editable_candidate_cache_installed_candidate_cache_extras_candidate_cacher   iter_installed_distributions_installed_dists)selfrN   rO   rP   rQ   rR   rS   rT   rU   rV   envrD   rD   rE   __init__Y   s(   


zFactory.__init__c                 C   s   | j S N)rb   rk   rD   rD   rE   rS      s   zFactory.force_reinstalllinkc                 C   s>   |j sd S t|j}|| jj rd S |j d}t|)Nz+ is not a supported wheel on this platform.)is_wheelr    filename	supportedr]   target_pythonget_tagsr   )rk   rp   wheelmsgrD   rD   rE   "_fail_if_link_is_unsupported_wheel   s   
z*Factory._fail_if_link_is_unsupported_wheelbaseextrasc                 C   sF   t ||f}z| j| }W |S  ty"   t||}|| j|< Y |S w rn   )idrh   KeyErrorr2   )rk   ry   rz   	cache_key	candidaterD   rD   rE   _make_extras_candidate   s   
zFactory._make_extras_candidaterZ   templatec                 C   sR   z| j |j }W n ty   t||| d}|| j |j< Y nw |s#|S | ||S )N)factory)rg   rX   r|   r/   r   )rk   rZ   rz   r   ry   rD   rD   rE   _make_candidate_from_dist   s   z!Factory._make_candidate_from_distnameversionc              
   C   s  || j v rd S |jrG|| jvrAzt||| ||d| j|< W n# ty@ } ztjd||ddid || j |< W Y d }~d S d }~ww | j| }n<|| jvr~zt||| ||d| j|< W n# ty} } ztjd||ddid || j |< W Y d }~d S d }~ww | j| }|s|S | 	||S )N)r   r   r   z3Discarding [blue underline]%s[/]: [yellow]%s[reset]markupT)extra)
rd   editablerf   r1   r   loggerinfore   r3   r   )rk   rp   rz   r   r   r   ery   rD   rD   rE   _make_candidate_from_link   s`   






	z!Factory._make_candidate_from_linkireqs	specifierhashesprefers_installedincompatible_idsc           	         s   |sdS |d j sJ dtj jt  |D ]}|j s#J d|j jM |jddM  t|jO  qdtt f fdd}dt	t
 f fd	d
}t|| |S )NrD   r   z)Candidates found on index must be PEP 508F)trust_internetrW   c                     sf   j rdS zj } W n
 ty   Y dS w j| jdds!dS j|  d}t|v r1dS |S )z6Get the candidate for the currently-installed version.NT)prereleases)rZ   rz   r   )rb   rj   r|   containsr   r   r{   )installed_distr~   )rz   r   r   rk   r   r   rD   rE   _get_installed_candidate   s"   z@Factory._iter_found_candidates.<locals>._get_installed_candidatec               	   3   s    j jd} t|  }tdd |D }dtdtfdd}|}t|D ]}|r0|s5|jj	r5q*t
jj|j |jd}|j|fV  q*d S )	N)project_namer   r   c                 s   s    | ]}|j jV  qd S rn   )rp   	is_yanked)rY   icanrD   rD   rE   	<genexpr>!  s    zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.<genexpr>r   rW   c                 S   s<   | D ]}|j dkr dS |j dkrq|jdrq dS dS )Nz===T==z.*F)operatorr   endswith)r   sprD   rD   rE   	is_pinned#  s   

zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.is_pinned)rp   rz   r   r   r   )r]   find_best_candidatelistiter_applicableallr   boolreversedrp   r   	functoolspartialr   r   )resulticans
all_yankedr   pinnedr   func)rz   r   r   rk   r   r   rD   rE   iter_index_candidate_infos  s.   zBFactory._iter_found_candidates.<locals>.iter_index_candidate_infos)reqr   r   	frozensetr   r   rz   r
   r+   r   r7   r6   )	rk   r   r   r   r   r   ireqr   r   rD   )rz   r   r   r   rk   r   r   rE   _iter_found_candidates   s&     (zFactory._iter_found_candidatesbase_requirementsc                 c   sL    |D ] }|  \}}|du rqt|}|dusJ d| ||V  qdS )a8  Produce explicit candidates from the base given an extra-ed package.

        :param base_requirements: Requirements known to the resolver. The
            requirements are guaranteed to not have extras.
        :param extras: The extras to inject into the explicit requirements'
            candidates.
        Nzno extras here)get_candidate_lookupr5   r   )rk   r   rz   r   lookup_cand_	base_candrD   rD   rE   #_iter_explicit_candidates_from_baseE  s   z+Factory._iter_explicit_candidates_from_base
identifier
constraintc                 c   sF    |j D ]}| | | j|t t||t|dd}|r |V  qdS )zProduce explicit candidates from constraints.

        This creates "fake" InstallRequirement objects that are basically clones
        of what "should" be the template, but with original_link set to link.
        Nrz   r   r   r   )linksrx   r   r   r"   r   )rk   r   r   r   rp   r~   rD   rD   rE   !_iter_candidates_from_constraints[  s   

z)Factory._iter_candidates_from_constraintsrH   incompatibilitiesc              	      s  t  }g } D ]}| \}	}
|	d ur||	 |
d ur#||
 q	tt t}|| 	
|jdt|j W d    n1 sIw   Y  |rjz|| j |d d W n
 tyi   Y dS w dd |
dD |s| | j j|S  fdd|D S )NrD   r   )r   c                 S   s   h | ]}t |qS rD   )r{   rY   crD   rD   rE   	<setcomp>      z*Factory.find_candidates.<locals>.<setcomp>c                 3   sD    | ] t  vr rt fd d D r V  qdS )c                 3   s    | ]}|  V  qd S rn   )is_satisfied_by)rY   r   r   rD   rE   r     s    z4Factory.find_candidates.<locals>.<genexpr>.<genexpr>N)r{   r   r   )rY   r   r   incompat_idsrH   r   rE   r     s    z*Factory.find_candidates.<locals>.<genexpr>)setr   addappend
contextlibsuppressr   r(   updater   getr   r   rz   r   r   r   r   r   )rk   r   rH   r   r   r   explicit_candidatesr   r   candr   parsed_requirementrD   r   rE   find_candidatesr  sT   	

zFactory.find_candidatesr   requested_extrasc                 C   s   | |std|j|j d S |jst|S | |j | j|jt	|j
||jr.t|jnd d d}|d u rG|js@| j|j tt|jS | |S )Nz6Ignoring %s: markers '%s' don't match your environmentr   )match_markersr   r   r   markersrp   r:   rx   r   r   rz   r   rd   r;   make_requirement_from_candidate)rk   r   r   r   rD   rD   rE   "_make_requirement_from_install_req  s,   

z*Factory._make_requirement_from_install_req
root_ireqsc                 C   s   t g i i }t|D ][\}}|jrDt|}|rt|| s q
|js'J dt|j}||jv r;|j|  |M  < q
t	
||j|< q
| j|dd}|d u rPq
|jr_|j|jvr_||j|j< |j| q
|S )NzConstraint must be namedrD   )r   )rG   	enumerater   r$   r   r   r   r   rI   r-   	from_ireqr   user_suppliedrJ   rH   r   )rk   r   	collectedir   problemr   r   rD   rD   rE   collect_root_requirements  s.   

z!Factory.collect_root_requirementsr~   c                 C   s   t |S rn   )r8   )rk   r~   rD   rD   rE   r     s   z'Factory.make_requirement_from_candidaterD   
comes_fromc                 C   s   |  ||}| ||S rn   )r`   r   )rk   r   r   r   r   rD   rD   rE   make_requirement_from_spec  s   z"Factory.make_requirement_from_specc                 C   s"   | j rd S t|sd S t|| jS rn   )rc   rK   r9   r_   )rk   r   rD   rD   rE    make_requires_python_requirement  s
   z(Factory.make_requires_python_requirementc                 C   s*   | j du s	| jjrdS | j j||t dS )a  Look up the link in the wheel cache.

        If ``preparer.require_hashes`` is True, don't use the wheel cache,
        because cached wheels, always built locally, have different hashes
        than the files downloaded from the index server and thus throw false
        hash mismatches. Furthermore, cached wheels at present have
        nondeterministic contents due to file modification times.
        N)rp   package_namesupported_tags)r^   rO   require_hashesget_cache_entryr&   )rk   rp   r   rD   rD   rE   get_wheel_cache_entry  s   zFactory.get_wheel_cache_entryc                 C   sZ   | j |j}|d u rd S | js|S |jr|S t r+|jr+d|j d|j }t	|d S )NzNWill not install to the user site because it will lack sys.path precedence to z in )
rj   r   r   ra   in_usersiter)   in_site_packagesraw_namelocationr   )rk   r~   rZ   messagerD   rD   rE   get_dist_to_uninstall"  s    zFactory.get_dist_to_uninstallcausesr=   c                 C   s   |sJ d| j j}t|dkr+t|d jj}d|d jjd| d|}t|S d| d}|D ]}|j	 }t|jj}|d	|d
| d7 }q3t|S )Nz,Requires-Python error reported with no causer*   r   zPackage z requires a different Python: z not in z%Packages require a different Python. z not in:
z (required by ))
r_   r   lenrK   r>   r   r?   r   r   format_for_error)rk   r   r   r   r   causepackagerD   rD   rE   _report_requires_python_error>  s"   
z%Factory._report_requires_python_errorr   r?   c                 C   s   |d u r	t |}n	| d|j d}| j|j}| j }dd tdd |D D }|r9tdd	|p7d	 td
|d	|pCd	 t |dkrPt
d td| S )Nz (from r   c                 S   s   g | ]}t |qS rD   )rK   )rY   vrD   rD   rE   
<listcomp>^  r   z?Factory._report_single_requirement_conflict.<locals>.<listcomp>c                 S   s   h | ]}|j qS rD   )r   r   rD   rD   rE   r   ^  s    z>Factory._report_single_requirement_conflict.<locals>.<setcomp>zJIgnored the following versions that require a different python version: %sz; nonezNCould not find a version that satisfies the requirement %s (from versions: %s), zrequirements.txtzHINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txtz#No matching distribution found for )rK   r   r]   find_all_candidatesr   requires_python_skipped_reasonssortedr   criticaljoinr   r   )rk   r   r?   req_dispcandsskipped_by_requires_pythonversionsrD   rD   rE   #_report_single_requirement_conflictT  s*   

z+Factory._report_single_requirement_conflictr   z,ResolutionImpossible[Requirement, Candidate]rI   c                    s  |j sJ d fdd|j D }|r td|S t|j dkr4|j d \}}|j|vr4 ||S dtt dtfd	d
}dtdtfdd}t	 }|j D ]\}}|d u r[|
 }	n||}	||	 qN|rn|t|}
nd}
d|
}t| d}t	 }|j D ],\}}|j|v r||j |d }|r||j d|j d }n|d }||
  }q|D ]}|| j}|d| | 7 }q|d d d d d }t| tdS )Nz)Installation error reported with no causec                    s*   g | ]}t |jtr|j js|qS rD   )
isinstancer>   r9   r   r_   )rY   r   ro   rD   rE   r     s    
z2Factory.get_installation_error.<locals>.<listcomp>zSequence[ConflictCause]r*   r   partsrW   c                 S   s2   t | dkr
| d S d| d d d | d  S )Nr*   r   r   z and )r   r   )r  rD   rD   rE   	text_join  s   z1Factory.get_installation_error.<locals>.text_joinr?   c                 S   sF   |   }|r	|js| j d| j S t|jtrt|jjS t|jS )Nr   )get_install_requirementr   r   r   r  r#   rK   )r?   r   rD   rD   rE   describe_trigger  s   

z8Factory.get_installation_error.<locals>.describe_triggerzthe requested packageszOCannot install {} because these package versions have conflicting dependencies.z
The conflict is caused by:z
     z depends on zThe user requested z%
    The user requested (constraint) z

zTo fix this you could try to:
z91. loosen the range of package versions you've specified
z92. remove package versions to allow pip attempt to solve zthe dependency conflict
zResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts)r   r   r   r   r   r   r   rK   r+   r   r   r   r   formatr   r   r   r   r   r   )rk   r   rI   requires_python_causesr   r?   r  r  triggerstriggerr   rw   relevant_constraintskeyspecrD   ro   rE   get_installation_errorv  sp   
	





	zFactory.get_installation_errorrn   )rD   );r@   rA   rB   r   r!   r%   r
   r   r   r   rL   rm   propertyrS   r   rx   r0   r   rK   r2   r   r   r#   r+   r   r   r,   r   r   r   r'   r   r   r   r.   r   r   r-   r   r   r   r   r   rG   r   r8   r   r   r   r   r   r   r   r   r   r   r   r   r  rD   rD   rD   rE   rM   X   s8   	

&	


>
a


F
 

	
	



"
rM   )\r   r   loggingtypingr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   "pip._vendor.packaging.requirementsr   Z pip._vendor.packaging.specifiersr   Zpip._vendor.packaging.utilsr   r   pip._vendor.resolvelibr   pip._internal.cacher   r   pip._internal.exceptionsr   r   r   r   r   "pip._internal.index.package_finderr   pip._internal.metadatar   r   pip._internal.models.linkr   pip._internal.models.wheelr     pip._internal.operations.preparer!   pip._internal.req.constructorsr"   Zpip._internal.req.req_installr#   r$   pip._internal.resolution.baser%   &pip._internal.utils.compatibility_tagsr&   pip._internal.utils.hashesr'   pip._internal.utils.packagingr(   pip._internal.utils.virtualenvr)   ry   r+   r,   r-   r.   
candidatesr/   r0   r1   r2   r3   r4   r5   found_candidatesr6   r7   rH   r8   r9   r:   r;   r<   r=   	getLoggerr@   r   rF   CacherG   rM   rD   rD   rD   rE   <module>   sD    @$	
