
0c@_;                 @   sP  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 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 m Z d d l m  Z  d d l! m" Z" d d l# m$ Z$ d d l% m& Z& e& rd d l' m( Z( d d l) m* Z* m+ Z+ m, Z, m- Z- d d l. m/ Z/ d d l0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 d d l6 m7 Z7 d d l# m8 Z8 m9 Z9 e j: e;  Z< Gd d   d e
  Z= Gd d   d e e=  Z> e$ j? e$ j@ e$ jA g ZB d d    ZC Gd! d"   d" e>  ZD d 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)
cmdoptions)Command)CommandContextMixIn)CommandErrorPreviousBuildDirError)LinkCollector)PackageFinder)SelectionPreferences)
Downloader)
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                   sX   e  Z d  Z d Z   f d d   Z e d d    Z d d   Z d d d	 d
  Z   S)SessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    c                s    t  t |   j   d  |  _ d  S)N)superr"   __init___session)self)	__class__ </tmp/pip-build-jynh7p1z/pip/pip/_internal/cli/req_command.pyr$   8   s    zSessionCommandMixin.__init__c             C   sl   g  } t  | d d  s= t  | d d  } | r= | j |  t  | d d  } | rb | j |  | pk d 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   sF   |  j  d k r? |  j |  j |   |  _  |  j  d k	 s? t  |  j  S)zGet a default-managed session.N)r%   enter_context_build_sessionAssertionError)r&   r1   r(   r(   r)   get_default_sessionL   s    z'SessionCommandMixin.get_default_sessionNc          
   C   s  | j  s% t j j | j   s% t  t d | j  rL t j j | j  d  n d  d | d  k	 rd | n | j d | j d |  j	 |   } | j
 r | j
 | _ | j r | j | _
 | j s | r | d  k	 r | n | j | _ | j rd | j d | j i | _ | j | j _ | S)Ncachehttpretriestrusted_hostsr2   https)	cache_dirospathisabsr8   r   joinr<   r=   r5   certverifyclient_certtimeoutproxyproxiesno_inputauth	prompting)r&   r1   r<   rG   sessionr(   r(   r)   r7   W   s"    %'					z"SessionCommandMixin._build_session)	__name__
__module____qualname____doc__r$   classmethodr5   r9   r7   r(   r(   )r'   r)   r"   3   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   sq   t  | d  s t  | j s' | j r+ d S|  j | d d d t d | j  } |  t | |  Wd QRXd S)z
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r*   Nr<   r   rG      )hasattrr8   disable_pip_version_checkr*   r7   minrG   r   )r&   r1   rM   r(   r(   r)   handle_pip_version_check   s    z*IndexGroupCommand.handle_pip_version_checkN)rN   rO   rP   rQ   rX   r(   r(   r(   r)   rS      s   rS   c                s%   d d        f d d   } | S)zNDecorator for common logic related to managing temporary
    directories.
    c             S   s%   x t  D] } |  j | d  q Wd  S)NF)KEEPABLE_TEMPDIR_TYPESZ
set_delete)registrytr(   r(   r)   configure_tempdir_registry   s    z0with_cleanup.<locals>.configure_tempdir_registryc                sh   |  j  d  k	 s t  | j r+   |  j   y  |  | |  SWn" t k
 rc   |  j     Yn Xd  S)N)Ztempdir_registryr8   no_cleanr   )r&   r1   args)r\   funcr(   r)   wrapper   s    	zwith_cleanup.<locals>.wrapperr(   )r_   r`   r(   )r\   r_   r)   with_cleanup   s    ra   c                   s   e  Z d  Z   f d d   Z e d d d d   Z e d d d d d d d d d	 d
   Z d d   Z e d d    Z d d d d  Z	   S)RequirementCommandc                s3   t  t |   j | |   |  j j t j    d  S)N)r#   rb   r$   cmd_opts
add_optionr   r]   )r&   r^   kw)r'   r(   r)   r$      s    zRequirementCommand.__init__Nc       
      C   s|   t  | d | j } |  j }	 |	 d k	 s0 t  t d |	 d | j d | d | d | j d | d	 | d
 | d | 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   rf   rA   r8   r   rh   rk   ro   )
Ztemp_build_dirr1   rl   rM   rn   rp   ri   rj   rm   Ztemp_build_dir_pathr(   r(   r)   make_requirement_preparer   s    				z,RequirementCommand.make_requirement_preparerFTzto-satisfy-onlyc             C   s  t  t d | j d |	 } d | j k r d d l } | j j j j j	 d |  d | d | d	 | d
 | d | j
 d | d | d | d | d |
 d d | j k  Sd d l } | j j j j j	 d |  d | d | d	 | d
 | d | j
 d | d | d | d | d |
  S)zF
        Create a Resolver instance for the given parameters.
        isolated
use_pep517z2020-resolverr   Npreparerrn   wheel_cachemake_install_reqrp   ignore_dependenciesignore_installedignore_requires_pythonforce_reinstallupgrade_strategypy_version_infoZ
lazy_wheelz	fast-deps)r   r   isolated_modeZfeatures_enabledZ,pip._internal.resolution.resolvelib.resolverZ	_internal
resolutionZ
resolvelibresolverZResolverrw   Z(pip._internal.resolution.legacy.resolverlegacy)rt   rn   r1   ru   rp   rx   ry   rz   r{   rs   r|   rv   pipr(   r(   r)   make_resolver   s@    				z RequirementCommand.make_resolverc             C   s  g  } xh | j  D]] } xT t | d d d | d | d | D]. } t | d | j d d } | j |  q; Wq WxB | D]: }	 t |	 d	 d | j d
 | j d d } | j |  qx WxB | j D]7 }	 t |	 d d d | j d
 | j } | j |  q Wxk | j	 D]` } xW t | d | d | d | D]7 } t | d | j d
 | j d d } | j |  q*WqWt
 d d   | D  rd | _ | p| j p| j	 s d |  j i }
 | j rt d j t |
 d d j | j      n t d j |
     | S)zS
        Parse command-line arguments into the corresponding requirements.
        
constraintTrn   r1   rM   rr   Zuser_suppliedFNrs   c             s   s   |  ] } | j  Vq d  S)N)has_hash_options).0reqr(   r(   r)   	<genexpr>Z  s    z6RequirementCommand.get_requirements.<locals>.<genexpr>namezXYou must give at least one requirement to {name} (maybe you meant "pip {name} {links}"?)links zHYou must give at least one requirement to {name} (see "pip help {name}"))constraintsr   r   r}   r.   r   rs   	editablesr   requirementsanyro   r   
find_linksr   formatdictrC   )r&   r^   r1   rn   rM   r   filenameZ
parsed_reqZ
req_to_addr   optsr(   r(   r)   get_requirements#  s\    										'z#RequirementCommand.get_requirementsc             C   s,   |  j  } | j   } | r( t j |  d S)zE
        Trace basic information about the provided objects.
        N)search_scopeZget_formatted_locationsloggerinfo)rn   r   	locationsr(   r(   r)   trace_basic_infok  s    	z#RequirementCommand.trace_basic_infoc             C   sa   t  j | d | } t d d d | j d | j d | j d |  } t j d | d	 | 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.
        r1   Zallow_yankedTformat_controlallow_all_prereleasesprefer_binaryry   link_collectorselection_prefstarget_python)r   creater
   r   prer   r	   )r&   r1   rM   r   ry   r   r   r(   r(   r)   _build_package_finderw  s    					z(RequirementCommand._build_package_finder)
rN   rO   rP   r$   staticmethodrq   r   r   r   r   r(   r(   )r'   r)   rb      s"   -Hrb   )ErQ   loggingr@   	functoolsr   Zpip._internal.clir   Zpip._internal.cli.base_commandr   Z!pip._internal.cli.command_contextr   Z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.downloadr   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   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr   optparser   Ztypingr   r   r   r   Zpip._internal.cacher   Z"pip._internal.models.target_pythonr   Zpip._internal.req.req_installr   Zpip._internal.req.req_trackerr   Zpip._internal.resolution.baser   r    r!   	getLoggerrN   r   r"   rS   Z	BUILD_ENVZEPHEM_WHEEL_CACHEZ	REQ_BUILDrY   ra   rb   r(   r(   r(   r)   <module>   sF   ""L 