a
    0f^                     @   s  d 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 ddlm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 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+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 e:e;Z<eee= e
e' f Z>deee?e?e?f e@ddddZAG dd de,ZBdS )ay  Dependency Resolution

The dependency resolution in pip is performed as follows:

for top-level requirements:
    a. only one spec allowed per project, regardless of conflicts or not.
       otherwise a "double requirement" exception is raised
    b. they override sub-dependency requirements.
for sub-dependencies
    a. "first found, wins" (where the order is breadth first)
    N)defaultdict)chain)DefaultDictIterableListOptionalSetTuple)
specifiers)Requirement)
WheelCache)BestVersionAlreadyInstalledDistributionNotFound	HashError
HashErrorsInstallationErrorNoneMetadataErrorUnsupportedPythonVersion)PackageFinder)BaseDistribution)Link)Wheel)RequirementPreparer)InstallRequirementcheck_invalid_constraint_type)RequirementSet)BaseResolverInstallRequirementProvider)compatibility_tags)get_supported)direct_url_from_link)
indent_log)normalize_version_info)check_requires_pythonF)distversion_infoignore_requires_pythonreturnc              
   C   s   zt | j}W n2 ty@ } zt| t |W Y d}~n
d}~0 0 zt||d}W n8 tjy } ztd| j	| W Y d}~dS d}~0 0 |rdS d
tt |}|rtd| j	|| dS td| j	d| d|dS )	a  
    Check whether the given Python version is compatible with a distribution's
    "Requires-Python" value.

    :param version_info: A 3-tuple of ints representing the Python
        major-minor-micro version to check.
    :param ignore_requires_python: Whether to ignore the "Requires-Python"
        value if the given Python version isn't compatible.

    :raises UnsupportedPythonVersion: When the given Python version isn't
        compatible.
    N)r%   z-Package %r has an invalid Requires-Python: %s.zBIgnoring failed Requires-Python check for package %r: %s not in %rzPackage z requires a different Python: z not in )strrequires_pythonFileNotFoundErrorr   r#   r
   InvalidSpecifierloggerwarningraw_namejoinmapdebugr   )r$   r%   r&   r*   eis_compatibleexcversion r7   a/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/resolution/legacy/resolver.py_check_dist_requires_python7   s@    $

r9   c                       s2  e Zd ZdZh dZd"eeee e	e
e
e
e
e
eeeedf  dd fddZee e
edd	d
Zd#eeee eee  eee ee f dddZee
dddZeddddZeee dddZeee dddZeddddZeedddZeeee dddZeee dd d!Z  ZS )$ResolverzResolves which packages need to be installed/uninstalled to perform     the requested operation without breaking the requirements of any package.
    >   to-satisfy-onlyeageronly-if-neededN.)preparerfinderwheel_cachemake_install_requse_user_siteignore_dependenciesignore_installedr&   force_reinstallupgrade_strategypy_version_infor'   c                    s   t    |
| jv sJ |d u r0tjd d }nt|}|| _|| _|| _|| _	|
| _
|	| _|| _|| _|| _|| _|| _tt| _d S )N   )super__init___allowed_strategiessysr%   r"   _py_version_infor>   r?   r@   rF   rE   rC   rD   r&   rB   _make_install_reqr   list_discovered_dependencies)selfr>   r?   r@   rA   rB   rC   rD   r&   rE   rF   rG   	__class__r7   r8   rJ   t   s"    
zResolver.__init__)	root_reqscheck_supported_wheelsr'   c                 C   s   t |d}|D ]}|jr t| | || qg }t }t|j|D ]P}z|| || W qD t	y } z||_
|| W Y d}~qDd}~0 0 qD|r||S )a  Resolve what operations need to be done

        As a side-effect of this method, the packages (and their dependencies)
        are downloaded, unpacked and prepared for installation. This
        preparation is done by ``pip.operations.prepare``.

        Once PyPI has static dependency metadata available, it would be
        possible to move the preparation to become a step separated from
        dependency resolution.
        )rU   N)r   
constraintr   _add_requirement_to_setr   r   all_requirementsextend_resolve_oner   reqappend)rQ   rT   rU   requirement_setr[   Zdiscovered_reqsZhash_errorsr5   r7   r7   r8   resolve   s     
"zResolver.resolve)r]   install_reqparent_req_nameextras_requestedr'   c           
      C   s  | |s$td|j|j g dfS |jrf|jjrft|jj}t	
 }|jrf||sft|j d|jr||du s|J d|js|| |gdfS z||j}W n ty   d}Y n0 |du o|o|j o|j|jko|jo|jo|jj|jjk}|rtd| d| d|jd|s8|| |g|fS |jsH|jsPg |fS |jop|jon|jj|jjk }	|	rtd	|j d
d|_|jrd|_ttt|jt|jB |_td||j |g|fS )a&  Add install_req as a requirement to install.

        :param parent_req_name: The name of the requirement that needed this
            added. The name is used because when multiple unnamed requirements
            resolve to the same name, we could otherwise end up with dependency
            links that point outside the Requirements set. parent_req must
            already be added. Note that None implies that this is a user
            supplied requirement, vs an inferred one.
        :param extras_requested: an iterable of extras used to evaluate the
            environment markers.
        :return: Additional requirements to scan. That is either [] if
            the requirement is not applicable, or [install_req] if the
            requirement is applicable and has just been added.
        z6Ignoring %s: markers '%s' don't match your environmentNz+ is not a supported wheel on this platform.z+a user supplied req shouldn't have a parentzDouble requirement given: z (already in z, name=)z#Could not satisfy constraints for 'zC': installation from path or url cannot be constrained to a versionFTzSetting %s extras to: %s)match_markersr-   infonamemarkerslinkis_wheelr   filenamer   r   rU   	supportedr   user_suppliedadd_unnamed_requirementget_requirementKeyErrorrV   extrasr[   	specifieradd_named_requirementpathtuplesortedsetr2   )
rQ   r]   r_   r`   ra   wheeltagsZexisting_reqZhas_conflicting_requirementZdoes_not_satisfy_constraintr7   r7   r8   rW      s    






	

z Resolver._add_requirement_to_setr[   r'   c                 C   s:   | j dkrdS | j dkrdS | j dks*J |jp4|jS d S )Nr;   Fr<   Tr=   )rF   rk   rV   rQ   r[   r7   r7   r8   _is_upgrade_allowed2  s    

zResolver._is_upgrade_allowedc                 C   s,   |j dusJ | jr|j jr"d|_d|_ dS )z4
        Set a requirement to be installed.
        NT)satisfied_byrB   in_usersiteshould_reinstallry   r7   r7   r8   _set_req_to_reinstall;  s    zResolver._set_req_to_reinstall)req_to_installr'   c                 C   s   | j r
dS || j |js dS | jr4| | dS | |sP| jdkrLdS dS |jsz| j	j
|dd W n$ ty~   Y dS  ty   Y n0 | | dS )a  Check if req_to_install should be skipped.

        This will check if the req is installed, and whether we should upgrade
        or reinstall it, taking into account all the relevant user options.

        After calling this req_to_install will only have satisfied_by set to
        None if the req_to_install is to be upgraded/reinstalled etc. Any
        other value will be a dist recording the current thing installed that
        satisfies the requirement.

        Note that for vcs urls and the like we can't assess skipping in this
        routine - we simply identify that we need to pull the thing down,
        then later on it is pulled down and introspected to assess upgrade/
        reinstalls etc.

        :return: A text reason for why it was skipped, or None.
        Nr=   z#already satisfied, skipping upgradezalready satisfiedT)upgradezalready up-to-date)rD   check_if_existsrB   r{   rE   r~   rz   rF   rg   r?   find_requirementr   r   )rQ   r   r7   r7   r8   _check_skip_installedF  s*    



zResolver._check_skip_installedc                 C   sT   |  |}| j||}|s d S |j}|jrP|jp4d}d| d| }t| |S )Nz<none given>zDThe candidate selected for download or install is a yanked version: z
Reason for being yanked: )rz   r?   r   rg   	is_yankedyanked_reasonr-   r.   )rQ   r[   r   best_candidaterg   reasonmsgr7   r7   r8   _find_requirement_link|  s    


zResolver._find_requirement_linkc                 C   s   |j du r| ||_ | jdu s(| jjr,dS |j dus>J d| jj|j |jt d}|durt	d|j  |j |j
u r|jr|j |_|jdur|j|_nt|j |jd|_|j |_ dS )af  Ensure that if a link can be found for this, that it is found.

        Note that req.link may still be None - if the requirement is already
        installed and not needed to be upgraded based on the return value of
        _is_upgrade_allowed().

        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 undeterministic
        contents due to file modification times.
        Nz1_find_requirement_link unexpectedly returned None)rg   package_namesupported_tagszUsing cached wheel link: %s)link_is_in_wheel_cache)rg   r   r@   r>   require_hashesget_cache_entryre   r   r-   r2   original_link
persistentZcached_wheel_source_linkorigindownload_infor    )rQ   r[   cache_entryr7   r7   r8   _populate_link  s(    


zResolver._populate_linkc                 C   s   |j r| j|S |jdu s J | |}|jr>| j||S | | | j|}| jsf|	| j
 |jr| jdkp| jp| jp|jjdk}|r| | ntd| |S )zzTakes a InstallRequirement and returns a single AbstractDist         representing a prepared variant of the same.
        Nr;   filez<Requirement already satisfied (use --upgrade to upgrade): %s)editabler>   prepare_editable_requirementr{   r   prepare_installed_requirementr   prepare_linked_requirementrD   r   rB   rF   rE   rg   schemer~   r-   rd   )rQ   r[   skip_reasonr$   Zshould_modifyr7   r7   r8   _get_dist_for  s2    




zResolver._get_dist_for)r]   r   r'   c           	         sH  j sjrg S d_}t|jjd g  ttt dd fdd}t	  j
duslJ j
sjsJ jdd js$jrtdd	j ttjt|  }|D ]}td
|j|j| qtt| tj@ }||D ]}|||d qW d   n1 s:0    Y   S )zxPrepare a single requirements file.

        :return: A list of additional InstallRequirements to also install.
        T)r%   r&   N)subreqra   r'   c                    sR    t| }j}j|||d\}}|rD|rDj| |  | d S )N)r`   ra   )rN   r)   re   rW   rP   r\   rY   )r   ra   Zsub_install_reqr`   Zto_scan_againZadd_to_parentZ	more_reqsr   r]   rQ   r7   r8   add_req  s    
z&Resolver._resolve_one.<locals>.add_req)r`   z!Installing extra requirements: %r,z%%s %s does not provide the extra '%s')ra   )rV   preparedr   r9   rM   r&   r   r   r)   r!   re   has_requirementrk   rW   rC   ro   r-   r2   r0   rt   ru   iter_provided_extrasr.   r/   r6   iter_dependencies)	rQ   r]   r   r$   r   Zmissing_requestedmissingZavailable_requestedr   r7   r   r8   rZ     sP    
 

0zResolver._resolve_one)req_setr'   c                    s@   g  t  tdd fdd|j D ]}| q. S )zCreate the installation order.

        The installation order is topological - requirements are installed
        before the requiring thing. We break cycles at an arbitrary point,
        and make no other guarantees.
        Nrx   c                    sN   | j s| v rd S | jrd S |  j| j D ]}| q2 |  d S )N)r{   rV   addrP   re   r\   )r[   deporderZordered_reqsschedulerQ   r7   r8   r   I  s    

z1Resolver.get_installation_order.<locals>.schedule)ru   r   requirementsvalues)rQ   r   r_   r7   r   r8   get_installation_order:  s    

zResolver.get_installation_order)N)NN) __name__
__module____qualname____doc__rK   r   r   r   r   r   boolr)   r	   intrJ   r   r   r   r^   r   rW   rz   r~   r   r   r   r   r   r   rZ   r   __classcell__r7   r7   rR   r8   r:   m   sX    ')  
s	6'0Tr:   )F)Cr   loggingrL   collectionsr   	itertoolsr   typingr   r   r   r   r   r	   Zpip._vendor.packagingr
   "pip._vendor.packaging.requirementsr   pip._internal.cacher   pip._internal.exceptionsr   r   r   r   r   r   r   "pip._internal.index.package_finderr   pip._internal.metadatar   pip._internal.models.linkr   pip._internal.models.wheelr    pip._internal.operations.preparer   Zpip._internal.req.req_installr   r   Zpip._internal.req.req_setr   pip._internal.resolution.baser   r   Zpip._internal.utilsr   &pip._internal.utils.compatibility_tagsr   &pip._internal.utils.direct_url_helpersr    pip._internal.utils.loggingr!   pip._internal.utils.miscr"   pip._internal.utils.packagingr#   	getLoggerr   r-   r)   ZDiscoveredDependenciesr   r   r9   r:   r7   r7   r7   r8   <module>   sB    $	
 6