U
    «ÃT_¯0  ã                   @   sj  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 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 ddlmZ ddlmZmZ ddl m!Z! e!�r*ddl"m#Z# ddl$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l0m1Z1 e 2e3¡Z4G dd„ deƒZ5G dd„ dee5ƒZ6G dd„ de6ƒZ7d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)ÚCommand)ÚCommandContextMixIn)ÚCommandError)ÚPackageFinder)ÚResolver)ÚSelectionPreferences)Ú
Downloader)Ú
PipSession)ÚRequirementPreparer)Úinstall_req_from_editableÚinstall_req_from_lineÚinstall_req_from_req_string)Úparse_requirements)Úmake_link_collectorÚpip_self_version_check)ÚMYPY_CHECK_RUNNING)ÚValues)ÚListÚOptionalÚTuple)Ú
WheelCache)ÚTargetPython)ÚRequirementSet)ÚRequirementTracker)ÚTempDirectoryc                       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__© úA/tmp/pip-unpacked-wheel-8u7dkzi1/pip/_internal/cli/req_command.pyr   2   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_urls7   s    

z#SessionCommandMixin._get_index_urlsc                 C   s0   | j dkr*|  |  |¡¡| _ | j dk	s*t‚| j S )zGet a default-managed session.N)r    Úenter_contextÚ_build_sessionÚAssertionError)r!   r-   r$   r$   r%   Úget_default_sessionF   s    
z'SessionCommandMixin.get_default_sessionNc                 C   s´   |j rtj |j ¡st‚t|j r0tj |j d¡nd |d k	r>|n|j|j|  	|¡d�}|j
rb|j
|_|jrp|j|_
|jsz|rŽ|d k	r†|n|j|_|jr¤|j|jdœ|_|j |j_|S )NÚhttp)ÚcacheÚretriesÚtrusted_hostsr.   )r6   Úhttps)Ú	cache_dirÚosÚpathÚisabsr4   r
   Újoinr8   r9   r1   ÚcertÚverifyÚclient_certÚtimeoutÚproxyÚproxiesÚno_inputÚauthÚ	prompting)r!   r-   r8   rC   Úsessionr$   r$   r%   r3   Q   s,    ÿù
ÿþz"SessionCommandMixin._build_session)NN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr1   r5   r3   Ú__classcell__r$   r$   r"   r%   r   -   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   sT   t |dƒst‚|js|jrdS | j|dtd|jƒd�}|� t||ƒ W 5 Q R X dS )z€
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r&   Nr   é   )r8   rC   )Úhasattrr4   Údisable_pip_version_checkr&   r3   ÚminrC   r   )r!   r-   rI   r$   r$   r%   Úhandle_pip_version_check�   s    
ýz*IndexGroupCommand.handle_pip_version_checkN)rJ   rK   rL   rM   rU   r$   r$   r$   r%   rP   y   s   rP   c                	   @   sF   e Zd Zeddd„ƒZeddd„ƒZd	d
„ Zedd„ ƒZddd„ZdS )ÚRequirementCommandNc           
      C   sB   t ||jd�}| j}	|	dk	s t‚t|	|j|||j||||j|d�
S )zQ
        Create a RequirementPreparer instance for the given parameters.
        )Úprogress_barN)
Ú	build_dirÚsrc_dirÚdownload_dirÚwheel_download_dirÚbuild_isolationÚreq_trackerÚ
downloaderÚfinderÚrequire_hashesÚuse_user_site)r	   rW   r=   r4   r   rY   r\   r`   )
Útemp_build_dirr-   r]   rI   r_   ra   rZ   r[   r^   Útemp_build_dir_pathr$   r$   r%   Úmake_requirement_preparerš   s    öz,RequirementCommand.make_requirement_preparerFTúto-satisfy-onlyc                 C   s0   t t|j||	d�}t| ||||j|||||
d�
S )zF
        Create a Resolver instance for the given parameters.
        )ÚisolatedÚwheel_cacheÚ
use_pep517)
Úpreparerr_   Úmake_install_reqra   Úignore_dependenciesÚignore_installedÚignore_requires_pythonÚforce_reinstallÚupgrade_strategyÚpy_version_info)r   r   Úisolated_moder   rk   )ri   r_   r-   rg   ra   rl   rm   rn   ro   rh   rp   rj   r$   r$   r%   Úmake_resolver»   s$    üöz RequirementCommand.make_resolverc              	   C   sP  |j D ].}t|d||||d�D ]}d|_| |¡ qq|D ]*}	t|	d|j|j|d�}d|_| |¡ q:|jD ](}	t|	|j|j|d�}d|_| |¡ ql|j	D ]0}t||||||jd�D ]}d|_| |¡ q¶qœ|j
t|j	 ¡ ƒ }
tdd„ |
D ƒƒrúd|_|�sL|j�sL|j	�sLd| ji}|j�r@td	t|d
 |j¡d� ƒ‚ntd| ƒ‚dS )z?
        Marshal cmd line args into a requirement set.
        T)Ú
constraintr_   r-   rI   rg   N)rf   rh   rg   )r_   r-   rI   rg   rh   c                 s   s   | ]}|j V  qd S r   )Úhas_hash_options)Ú.0Úreqr$   r$   r%   Ú	<genexpr>  s     z>RequirementCommand.populate_requirement_set.<locals>.<genexpr>Únamez^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)ú )ÚlinkszLYou must give at least one requirement to %(name)s (see "pip help %(name)s"))Úconstraintsr   Ú	is_directÚadd_requirementr   rq   rh   Ú	editablesr   ÚrequirementsÚunnamed_requirementsÚlistÚvaluesÚanyr`   rx   Ú
find_linksr   Údictr?   )r!   Úrequirement_setÚargsr-   r_   rI   rg   ÚfilenameÚ
req_to_addrv   r   Úoptsr$   r$   r%   Úpopulate_requirement_setà   sx    
   ý
  ý
ü
  ü
ÿÿ
þÿÿÿz+RequirementCommand.populate_requirement_setc                 C   s    | j }| ¡ }|rt |¡ dS )zE
        Trace basic information about the provided objects.
        N)Úsearch_scopeÚget_formatted_locationsÚloggerÚinfo)r_   rŒ   Ú	locationsr$   r$   r%   Útrace_basic_info&  s    z#RequirementCommand.trace_basic_infoc                 C   s4   t ||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.
        )r-   T)Úallow_yankedÚformat_controlÚallow_all_prereleasesÚprefer_binaryrm   )Úlink_collectorÚselection_prefsÚtarget_python)r   r   r“   Úprer•   r   Úcreate)r!   r-   rI   r˜   rm   r–   r—   r$   r$   r%   Ú_build_package_finder2  s    ûýz(RequirementCommand._build_package_finder)NN)NFTFFre   NN)NN)	rJ   rK   rL   Ústaticmethodrd   rr   r‹   r‘   r›   r$   r$   r$   r%   rV   ˜   s(     ø         õ$F
  ûrV   )8rM   Úloggingr<   Ú	functoolsr   Úpip._internal.cli.base_commandr   Ú!pip._internal.cli.command_contextr   Úpip._internal.exceptionsr   Ú"pip._internal.index.package_finderr   Úpip._internal.legacy_resolver   Ú$pip._internal.models.selection_prefsr   Úpip._internal.network.downloadr	   Úpip._internal.network.sessionr
   Ú pip._internal.operations.preparer   Úpip._internal.req.constructorsr   r   r   Zpip._internal.req.req_filer   Ú!pip._internal.self_outdated_checkr   r   Úpip._internal.utils.typingr   Úoptparser   Útypingr   r   r   Úpip._internal.cacher   Ú"pip._internal.models.target_pythonr   Zpip._internal.req.req_setr   Úpip._internal.req.req_trackerr   Úpip._internal.utils.temp_dirr   Ú	getLoggerrJ   rŽ   r   rP   rV   r$   r$   r$   r%   Ú<module>   s8   
L