3
gh                 @   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#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l0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> ddl?m@Z@mAZAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZMmNZN ddlOmPZPmQZQmRZRmSZS erd dlmTZT G dd deTZUejVeWZXedZYee+eYf ZZG dd deZ[G 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InstallationSubprocessError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S )ConflictCauseN)__name__
__module____qualname__r:   requirementr,   parent rD   rD   i/var/www/tester-filtro-web/env/lib/python3.6/site-packages/pip/_internal/resolution/resolvelib/factory.pyr>   H   s   
r>   Cc               @   s.   e Zd ZU ee eeef 	eee
f dS )CollectedRootRequirementsN)r?   r@   rA   r   r/   requirementsr   strr.   constraintsintuser_requestedrD   rD   rD   rE   rG   S   s   
rG   c               @   s,  e Zd Zd@eeeee eeeeee	e
df  dd
ddZeedddZedd	d
dZeee edddZeee eedddZeee eee ee ee dddZee eeeee
 e e dddZ!e e" ee e#e dddZ$ee%ee#e dddZ&ee'ee e" f e'ee#e f e%ee e ddd Z(ee e ee" d!d"d#Z)e*e e+d$d%d&Z,ee-d'd(d)Z.f feee e e ee" d*d+d,Z/eee" d-d.d/Z0eee ee1 d0d1d2Z2eee d'd3d4Z3ed5 e4d6d7d8Z5e"ee e6d9d:d;Z7d<e8ee%f e9d=d>d?Z:dS )A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 | _|svt }
dd |
jddD | _ni | _d S )Nc             S   s   i | ]}||j qS rD   )canonical_name).0distrD   rD   rE   
<dictcomp>y   s   z$Factory.__init__.<locals>.<dictcomp>F)
local_only)_finderrO   _wheel_cacher5   _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__Z   s$    
zFactory.__init__)rW   c             C   s   | j S )N)rb   )rk   rD   rD   rE   rS      s    zFactory.force_reinstall)linkrW   c             C   sB   |j s
d S t|j}|j| jjj r*d S |j d}t|d S )Nz+ is not a supported wheel on this platform.)is_wheelr!   filename	supportedr]   target_pythonget_tagsr   )rk   rn   wheelmsgrD   rD   rE   "_fail_if_link_is_unsupported_wheel   s    
z*Factory._fail_if_link_is_unsupported_wheel)baseextrasrW   c             C   sH   t ||f}y| j| }W n( tk
rB   t||}|| j|< Y nX |S )N)idrh   KeyErrorr3   )rk   rw   rx   	cache_key	candidaterD   rD   rE   _make_extras_candidate   s    
zFactory._make_extras_candidate)rZ   rx   templaterW   c             C   sT   y| j |j }W n. tk
r>   t||| d}|| j |j< Y nX |sH|S | j||S )N)factory)rg   rX   rz   r0   r}   )rk   rZ   rx   r~   rw   rD   rD   rE   _make_candidate_from_dist   s    z!Factory._make_candidate_from_dist)rn   rx   r~   nameversionrW   c             C   s  || j krd S |jr|| jkrxyt||| ||d| j|< W n< ttfk
rv } ztjd|| || j |< d S d }~X nX | j| }nn|| jkryt	||| ||d| j|< W n< ttfk
r } ztjd|| || j |< d S d }~X nX | j| }| s|S | j
||S )N)r   r   r   zDiscarding %s. %s)rd   editablerf   r2   r   r   loggerwarningre   r4   r}   )rk   rn   rx   r~   r   r   erw   rD   rD   rE   _make_candidate_from_link   s@    





z!Factory._make_candidate_from_link)ireqs	specifierhashesprefers_installedincompatible_idsrW   c       	         s   |sf S |d j stdtj jt  xD|D ]<}|j sHtd|j jM |jddM  t|jO  q6W tt	 d fdd}t
t d fdd	}t|| |S )
Nr   z)Candidates found on index must be PEP 508F)trust_internet)rW   c                 sf   j r
dS yj } W n tk
r,   dS X j| jddsBdS j|  d}t|krbdS |S )z6Get the candidate for the currently-installed version.NT)prereleases)rZ   rx   r~   )rb   rj   rz   containsr   r   ry   )installed_distr|   )rx   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| j }tdd |D }xHt|D ]<}| rN|jjrNq:tj	j
|j |jd}|j|fV  q:W d S )N)project_namer   r   c             s   s   | ]}|j jV  qd S )N)rn   	is_yanked)rY   icanrD   rD   rE   	<genexpr>  s    zUFactory._iter_found_candidates.<locals>.iter_index_candidate_infos.<locals>.<genexpr>)rn   rx   r~   r   r   )r]   find_best_candidatelistiter_applicableallreversedrn   r   	functoolspartialr   r   )resultZicansZ
all_yankedr   func)rx   r   r   rk   r   r~   rD   rE   iter_index_candidate_infos  s"    
zBFactory._iter_found_candidates.<locals>.iter_index_candidate_infos)reqAssertionErrorr   r   	frozensetr   r   rx   r
   r,   r   r8   r7   )	rk   r   r   r   r   r   ireqr   r   rD   )rx   r   r   r   rk   r   r~   rE   _iter_found_candidates   s$    
  zFactory._iter_found_candidates)base_requirementsrx   rW   c             c   sN   xH|D ]@}|j  \}}|dkr qt|}|dk	s8td| j||V  qW 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_lookupr6   r   r}   )rk   r   rx   r   Zlookup_cand_Z	base_candrD   rD   rE   #_iter_explicit_candidates_from_base.  s    
z+Factory._iter_explicit_candidates_from_base)
identifier
constraintr~   rW   c             c   sH   xB|j D ]8}| j| | j|t t||t|dd}|r|V  qW 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)rx   r~   r   r   )linksrv   r   r   r#   r   )rk   r   r   r~   rn   r|   rD   rD   rE   !_iter_candidates_from_constraintsD  s    
z)Factory._iter_candidates_from_constraints)r   rH   incompatibilitiesr   r   rW   c                s  t  }g }x@ D ]4}|j \}	}
|	d k	r6|j|	 |
d k	r|j|
 qW tjt0 t}|j| j	j
|jf t|j W d Q R X |ry|j| j |d d W n tk
r   f S X dd |j
f D |s| j| j j|S  fdd|D S )Nr   )r~   c             S   s   h | ]}t |qS rD   )ry   )rY   crD   rD   rE   	<setcomp>  s    z*Factory.find_candidates.<locals>.<setcomp>c             3   sB   | ]: t  krj rt fd d D r V  qdS )c             3   s   | ]}|j  V  qd S )N)is_satisfied_by)rY   r   )r   rD   rE   r     s    z4Factory.find_candidates.<locals>.<genexpr>.<genexpr>N)ry   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   rx   r   r   r   r   r   )rk   r   rH   r   r   r   Zexplicit_candidatesr   r   candr   Zparsed_requirementrD   )r   r   r   rH   rE   find_candidates[  sB    	
zFactory.find_candidates)r   requested_extrasrW   c             C   s   |j |s tjd|j|j d S |js.t|S | j|j | j|jt	|j
||jr\t|jnd d d}|d kr|js| j|j tt|jS | j|S )Nz6Ignoring %s: markers '%s' don't match your environment)rx   r~   r   r   )match_markersr   infor   markersrn   r;   rv   r   r   rx   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_ireqsrW   c             C   s   t g i i }xt|D ]\}}|jrt|}|r8t||j sBq|jsPtdt|j}||j	krx|j	|  |M  < qt
j||j	|< q| j|f d}|d krq|jr|j|jkr||j|j< |jj| qW |S )NzConstraint must be named)r   )rG   	enumerater   r%   r   r   r   r   r   rJ   r.   	from_ireqr   user_suppliedrL   rH   r   )rk   r   	collectedir   problemr   r   rD   rD   rE   collect_root_requirements  s,    

z!Factory.collect_root_requirements)r|   rW   c             C   s   t |S )N)r9   )rk   r|   rD   rD   rE   r     s    z'Factory.make_requirement_from_candidate)r   
comes_fromr   rW   c             C   s   | j ||}| j||S )N)r`   r   )rk   r   r   r   r   rD   rD   rE   make_requirement_from_spec  s    z"Factory.make_requirement_from_spec)r   rW   c             C   s"   | j r
d S t|sd S t|| jS )N)rc   rI   r:   r_   )rk   r   rD   rD   rE    make_requires_python_requirement  s
    z(Factory.make_requires_python_requirement)rn   r   rW   c             C   s*   | j dk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)rn   package_namesupported_tags)r^   rO   require_hashesget_cache_entryr'   )rk   rn   r   rD   rD   rE   get_wheel_cache_entry  s    zFactory.get_wheel_cache_entryc             C   sZ   | j j|j}|d krd S | js$|S |jr.|S t rV|jrVd|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_uninstallr>   )causesrW   c             C   s   |st d| jj}t|dkrVt|d jj}d|d jjd| d|}t	|S d| d}x8|D ]0}|jj
 }t|jj}|d	|d
| d7 }qhW t	|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_   r   lenrI   rB   r   rC   r   r   format_for_error)rk   r   r   r   r   causepackagerD   rD   rE   _report_requires_python_error'  s    

z%Factory._report_requires_python_error)r   rC   rW   c             C   s   |d krt |}n| d|j d}| jj|j}dd tdd |D D }tjd|dj|pbd	 t |d
kr|tj	d t
d| S )Nz (from r   c             S   s   g | ]}t |qS rD   )rI   )rY   vrD   rD   rE   
<listcomp>F  s    z?Factory._report_single_requirement_conflict.<locals>.<listcomp>c             S   s   h | ]
}|j qS rD   )r   )rY   r   rD   rD   rE   r   F  s    z>Factory._report_single_requirement_conflict.<locals>.<setcomp>zNCould not find a version that satisfies the requirement %s (from versions: %s)z, nonez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 )rI   r   r]   find_all_candidatesr   sortedr   criticaljoinr   r   )rk   r   rC   Zreq_dispZcandsversionsrD   rD   rE   #_report_single_requirement_conflict=  s    
z+Factory._report_single_requirement_conflictz,ResolutionImpossible[Requirement, Candidate])r   rJ   rW   c                s  |j std fdd|j D }|r6 jtd|S t|j dkrh|j d \}}|j|krh j||S tt tddd	}t	td
dd}t
 }x6|j D ],\}}|d kr|j }	n||}	|j|	 qW |r|t|}
nd}
dj|
}tj| d}t
 }xh|j D ]^\}}|j|kr&|j|j |d }|rN||j d|j d }n|d }||j  }qW x*|D ]"}|| j}|d| | 7 }qnW |d d d d d }tj| tdS )Nz)Installation error reported with no causec                s,   g | ]$}t |jtr|jj j r|qS rD   )
isinstancerB   r:   r   r_   )rY   r   )rk   rD   rE   r   c  s   z2Factory.get_installation_error.<locals>.<listcomp>zSequence[ConflictCause]r+   r   )partsrW   c             S   s2   t | dkr| d S dj| d d d | d  S )Nr+   r   z, z and r   )r   r   )r   rD   rD   rE   	text_join}  s    z1Factory.get_installation_error.<locals>.text_join)rC   rW   c             S   sJ   | j  }| s|j r(| j d| j S t|jtr@t|jjS t|jS )Nz==)get_install_requirementr   r   r   r   r$   rI   )rC   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
znResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies)r   r   r   r   r   r   r   r   rI   r,   r   r   r   r   formatr   r   r   r   r   r   )rk   r   rJ   Zrequires_python_causesr   rC   r   r   ZtriggersZtriggerr   ru   Zrelevant_constraintskeyspecrD   )rk   rE   get_installation_errorX  sR    







zFactory.get_installation_error)N);r?   r@   rA   r   r"   r&   r
   r   boolr   rK   rm   propertyrS   r    rv   r1   r   rI   r3   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   r9   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   rD   rD   rE   rM   Y   sp   $
.O@	
rM   )]r   r   loggingtypingr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   Z"pip._vendor.packaging.requirementsr   Z pip._vendor.packaging.specifiersr   pip._vendor.packaging.utilsr   r   pip._vendor.resolvelibr   pip._internal.cacher   r   pip._internal.exceptionsr   r   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#   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*   rw   r,   r-   r.   r/   
candidatesr0   r1   r2   r3   r4   r5   r6   Zfound_candidatesr7   r8   rH   r9   r:   r;   r<   r=   r>   	getLoggerr?   r   rF   CacherG   rM   rD   rD   rD   rE   <module>   sB   @ $	
