a
    eG@                     @   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 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 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 ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& e&rZddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl#m8Z8m9Z9 e:e;Z<G dd deZ=G dd de
e=Z>e$j?e$j@e$jAgZBdd  ZCG d!d" d"e>ZDdS )#a  Contains the Command base classes that depend on PipSession.

The classes in this module are in a separate module so the commands not
needing download / PackageFinder capability don't unnecessarily import the
PackageFinder machinery and all its vendored dependencies, etc.
    N)partial)PY2)
cmdoptions)Command)CommandContextMixIn)CommandErrorPreviousBuildDirError)LinkCollector)PackageFinder)SelectionPreferences)
PipSession)RequirementPreparer)install_req_from_editableinstall_req_from_line#install_req_from_parsed_requirementinstall_req_from_req_string)parse_requirements)pip_self_version_check)tempdir_kinds)MYPY_CHECK_RUNNING)Values)AnyListOptionalTuple)
WheelCache)TargetPython)InstallRequirement)RequirementTracker)BaseResolver)TempDirectoryTempDirectoryTypeRegistryc                       s>   e Zd ZdZ fddZedd Zdd Zdd	d
Z  Z	S )SessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    c                    s   t t|   d | _d S N)superr"   __init___session)self	__class__ Q/var/www/sunrise/env/lib/python3.9/site-packages/pip/_internal/cli/req_command.pyr%   6   s    zSessionCommandMixin.__init__c                 C   sL   g }t |dds*t |dd}|r*|| t |dd}|rD|| |pJdS )z7Return a list of index urls from user-provided options.no_indexF	index_urlNextra_index_urls)getattrappendextend)clsoptions
index_urlsurlurlsr*   r*   r+   _get_index_urls;   s    

z#SessionCommandMixin._get_index_urlsc                 C   s0   | j du r*| | || _ | j dus*J | j S )zGet a default-managed session.N)r&   enter_context_build_session)r'   r3   r*   r*   r+   get_default_sessionJ   s    
z'SessionCommandMixin.get_default_sessionNc                 C   s   |j rtj|j sJ t|j r0tj|j dnd |d ur>|n|j|j| |d}|j	rb|j	|_
|jrp|j|_	|jsz|r|d ur|n|j|_|jr|j|jd|_|j |j_|S )Nhttp)cacheretriestrusted_hostsr4   )r;   https)	cache_dirospathisabsr   joinr=   r>   r7   certverifyclient_certtimeoutproxyproxiesno_inputauthZ	prompting)r'   r3   r=   rH   sessionr*   r*   r+   r9   U   s,    
z"SessionCommandMixin._build_session)NN)
__name__
__module____qualname____doc__r%   classmethodr7   r:   r9   __classcell__r*   r*   r(   r+   r"   1   s   
r"   c                   @   s   e Zd ZdZdd ZdS )IndexGroupCommandz
    Abstract base class for commands with the index_group options.

    This also corresponds to the commands that permit the pip version check.
    c                 C   sh   t |dsJ |js|jrdS | j|dtd|jd}| t|| W d   n1 sZ0    Y  dS )z
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r,   Nr      )r=   rH   )hasattrdisable_pip_version_checkr,   r9   minrH   r   )r'   r3   rM   r*   r*   r+   handle_pip_version_check   s    
z*IndexGroupCommand.handle_pip_version_checkN)rN   rO   rP   rQ   rY   r*   r*   r*   r+   rT   }   s   rT   c                    s   dd   fdd}|S )zNDecorator for common logic related to managing temporary
    directories.
    c                 S   s   t D ]}| |d qd S )NF)KEEPABLE_TEMPDIR_TYPES
set_delete)registrytr*   r*   r+   configure_tempdir_registry   s    z0with_cleanup.<locals>.configure_tempdir_registryc                    sP   | j d usJ |jr | j  z| ||W S  tyJ    | j   Y n0 d S r#   )tempdir_registryno_cleanr   )r'   r3   argsr^   funcr*   r+   wrapper   s    

zwith_cleanup.<locals>.wrapperr*   )rc   rd   r*   rb   r+   with_cleanup   s    re   c                	       sb   e Zd Z fddZedd ZedddZedddZdd Z	edd Z
dddZ  ZS )RequirementCommandc                    s*   t t| j|i | | jt  d S r#   )r$   rf   r%   cmd_opts
add_optionr   r`   )r'   ra   kwr(   r*   r+   r%      s    zRequirementCommand.__init__c                 C   s(   t rd| jv rdS dS d| jv r$dS dS )zEDetermines which resolver should be used, based on the given options.2020-resolverlegacyzlegacy-resolver)r   features_enableddeprecated_features_enabledr3   r*   r*   r+   determine_resolver_variant   s    

z-RequirementCommand.determine_resolver_variantNc                 C   s|   |j }|dusJ | |}	|	dkr>d|jv }
|
rVtd nd}
d|jv rVtd t||j||j|||j||j	||
dS )zQ
        Create a RequirementPreparer instance for the given parameters.
        Nrj   z	fast-depszpip is using lazily downloaded wheels using HTTP range requests to obtain dependency information. This experimental feature is enabled through --use-feature=fast-deps and it is not ready for production.Fz;fast-deps has no effect when used with the legacy resolver.)	build_dirsrc_dirdownload_dirbuild_isolationreq_trackerrM   progress_barfinderrequire_hashesuse_user_site
lazy_wheel)
rB   ro   rl   loggerwarningr   rq   rs   ru   rw   )r2   temp_build_dirr3   rt   rM   rv   rx   rr   Ztemp_build_dir_pathresolver_variantry   r*   r*   r+   make_requirement_preparer   s6    


z,RequirementCommand.make_requirement_preparerFTto-satisfy-onlyc                 C   s   t t|j|
d}| |}|dkrTddl}|jjjjj	||||||j
||||	|dS ddl}|jjjjj	||||||j
||||	|dS )zF
        Create a Resolver instance for the given parameters.
        )isolated
use_pep517rj   r   N)preparerrv   wheel_cachemake_install_reqrx   ignore_dependenciesignore_installedignore_requires_pythonforce_reinstallupgrade_strategypy_version_info)r   r   isolated_modero   Z,pip._internal.resolution.resolvelib.resolver	_internal
resolution
resolvelibresolverResolverr   Z(pip._internal.resolution.legacy.resolverrk   )r2   r   rv   r3   r   rx   r   r   r   r   r   r   r   r}   pipr*   r*   r+   make_resolver
  sF    
z RequirementCommand.make_resolverc              	   C   sT  g }|j D ]6}t|d|||dD ]}t||jdd}|| q q
|D ]$}	t|	d|j|jdd}|| qF|jD ]"}	t|	d|j|jd}|| qr|j	D ]8}t||||dD ]"}t||j|jdd}|| qqt
d	d
 |D rd|_|sP|jsP|j	sPd| ji}
|jr<tdjf i t|
d|jdntdjf i |
|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)Z
constraintrv   r3   rM   F)r   user_suppliedN)r   r   r   )r   r   r   )rv   r3   rM   c                 s   s   | ]}|j V  qd S r#   )Zhas_hash_options).0reqr*   r*   r+   	<genexpr>|      z6RequirementCommand.get_requirements.<locals>.<genexpr>namezXYou must give at least one requirement to {name} (maybe you meant "pip {name} {links}"?) )linkszHYou must give at least one requirement to {name} (see "pip help {name}"))constraintsr   r   r   r0   r   r   	editablesr   requirementsanyrw   r   
find_linksr   formatdictrD   )r'   ra   r3   rv   rM   r   filenameZ
parsed_reqZ
req_to_addr   optsr*   r*   r+   get_requirementsE  sp    





z#RequirementCommand.get_requirementsc                 C   s    | j }| }|rt| dS )zE
        Trace basic information about the provided objects.
        N)search_scopeZget_formatted_locationsrz   info)rv   r   	locationsr*   r*   r+   trace_basic_info  s    z#RequirementCommand.trace_basic_infoc                 C   s6   t j||d}td|j|j|j|d}tj|||dS )z
        Create a package finder appropriate to this requirement command.

        :param ignore_requires_python: Whether to ignore incompatible
            "Requires-Python" values in links. Defaults to False.
        rn   T)Zallow_yankedformat_controlZallow_all_prereleasesprefer_binaryr   )link_collectorselection_prefstarget_python)r	   creater   r   prer   r
   )r'   r3   rM   r   r   r   r   r*   r*   r+   _build_package_finder  s    z(RequirementCommand._build_package_finder)N)NFTFFr   NN)NN)rN   rO   rP   r%   staticmethodro   rR   r~   r   r   r   r   rS   r*   r*   r(   r+   rf      s,   
	 1        :H
  rf   )ErQ   loggingrA   	functoolsr   Zpip._vendor.sixr   pip._internal.clir   Zpip._internal.cli.base_commandr   Z!pip._internal.cli.command_contextr   pip._internal.exceptionsr   r   Zpip._internal.index.collectorr	   Z"pip._internal.index.package_finderr
   Z$pip._internal.models.selection_prefsr   Zpip._internal.network.sessionr   Z pip._internal.operations.preparer   Zpip._internal.req.constructorsr   r   r   r   Zpip._internal.req.req_filer   Z!pip._internal.self_outdated_checkr   pip._internal.utils.temp_dirr   pip._internal.utils.typingr   optparser   typingr   r   r   r   pip._internal.cacher   "pip._internal.models.target_pythonr   pip._internal.req.req_installr   pip._internal.req.req_trackerr   Zpip._internal.resolution.baser   r    r!   	getLoggerrN   rz   r"   rT   	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILDrZ   re   rf   r*   r*   r*   r+   <module>   sH   
L 