
'^c           @@  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l 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 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" 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/ m0 Z0 d  d l1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 m9 Z9 e4 rCd  d l m: Z: d  d l; m< Z< m= Z= m> Z> m? Z? d  d l@ mA ZA d  d lB mC ZC d  d l7 mD ZD n  e jE eF  ZG d   ZH d e f d     YZI d    ZJ d!   ZK eL eL eL eM d"  ZN d#   ZO d$   ZP d S(%   i    (   t   absolute_importN(   t   SUPPRESS_HELP(   t   pkg_resources(   t   canonicalize_name(   t
   WheelCache(   t
   cmdoptions(   t   make_target_python(   t   RequirementCommand(   t   ERRORt   SUCCESS(   t   CommandErrort   InstallationErrort   PreviousBuildDirError(   t   distutils_scheme(   t   check_install_conflicts(   t   RequirementSett   install_given_reqs(   t   get_requirement_tracker(   t
   deprecated(   t   parse_distutils_args(   t   test_writable_dir(   t
   ensure_dirt   get_installed_versiont(   protect_pip_from_modification_on_windowst   write_output(   t   TempDirectory(   t   MYPY_CHECK_RUNNING(   t   virtualenv_no_global(   t   buildt    should_build_for_install_command(   t   Values(   t   Anyt   Iterablet   Listt   Optional(   t   FormatControl(   t   InstallRequirement(   t   BinaryAllowedPredicatec         @  s     f d   } | S(   Nc         @  s5   |  j  r t St |  j  }   j |  } d | k S(   Nt   binary(   t
   use_pep517t   TrueR   t   namet   get_allowed_formats(   t   reqt   canonical_namet   allowed_formats(   t   format_control(    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   check_binary_allowed?   s
    	(    (   R.   R/   (    (   R.   s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   get_check_binary_allowed=   s    t   InstallCommandc           B@  s8   e  Z d  Z d Z d   Z d   Z d   Z d   Z RS(   sI  
    Install packages from:

    - PyPI (and other indexes) using requirement specifiers.
    - VCS project urls.
    - Local project directories.
    - Local or remote source archives.

    pip also supports installing from "requirements files", which provide
    an easy way to specify a whole environment to be installed.
    s%  
      %prog [options] <requirement specifier> [package-index-options] ...
      %prog [options] -r <requirements file> [package-index-options] ...
      %prog [options] [-e] <vcs project url> ...
      %prog [options] [-e] <local project path> ...
      %prog [options] <archive url/path> ...c         O@  s  t  t |   j | |   |  j } | j t j    | j t j    | j t j    | j t j	    | j t j
    | j d d d d d d d d  d d	 t j |  | j d
 d d d d d d | j d d d d d d t | j d d d d d d d  d d | j d d d d d d d  d d | j t j    | j t j    | j d d d d d d d d | j d d d d d d d d g d d  | j d! d d" d d d d# | j d$ d% d d& d d d d' | j t j    | j t j    | j t j    | j t j    | j t j    | j t j    | j d( d d d d) d t d d* | j d+ d d d d) d d, | j d- d d d d. d t d d/ | j d0 d d d d1 d t d d2 | j t j    | j t j    | j t j    | j t j    | j t j    | j t j    t j t j |  j  } |  j j  d3 |  |  j j  d3 |  d  S(4   Ns   -ts   --targett   destt
   target_dirt   metavart   dirt   defaultt   helps   Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with new versions.s   --usert   use_user_sitet   actiont
   store_trues   Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. (See the Python documentation for site.USER_BASE for full details.)s	   --no-usert   store_falses   --roott	   root_paths=   Install everything relative to this alternate root directory.s   --prefixt   prefix_pathsI   Installation prefix where lib, bin and other top-level folders are placeds   -Us	   --upgradet   upgrades   Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.s   --upgrade-strategyt   upgrade_strategys   only-if-neededt   choicest   eagersG  Determines how dependency upgrading should be handled [default: %default]. "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). "only-if-needed" -  are upgraded only when they do not satisfy the requirements of the upgraded package(s).s   --force-reinstallt   force_reinstalls;   Reinstall all packages even if they are already up-to-date.s   -Is   --ignore-installedt   ignore_installeds   Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a different package manager!s	   --compilet   compiles'   Compile Python source files to bytecodes   --no-compiles.   Do not compile Python source files to bytecodes   --no-warn-script-locationt   warn_script_locations0   Do not warn when installing scripts outside PATHs   --no-warn-conflictst   warn_about_conflictss%   Do not warn about broken dependenciesi    (!   t   superR1   t   __init__t   cmd_optst
   add_optionR   t   requirementst   constraintst   no_depst   pret   editablet   Nonet   add_target_python_optionsR   t	   build_dirt   srct   ignore_requires_pythont   no_build_isolationR'   t   no_use_pep517t   install_optionst   global_optionsR(   t	   no_binaryt   only_binaryt   prefer_binaryt   no_cleant   require_hashest   progress_bart   make_option_groupt   index_groupt   parsert   insert_option_group(   t   selft   argst   kwRI   t
   index_opts(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyRH   ^   s    					c   (      C@  s  t  j |  d } | j r( | j } n  t  j | d t | j pG g  } t | j d | j	 d | j
 d | j d | j | _ d  } d  } | j
 rt | _ t j j | j
  | _
 t j j | j
  r t j j | j
  r t d   n  t d d	  } | j } n  | j pg  } |  j |  } t |  }	 |  j d
 | d | d |	 d | j  }
 | j pk| j } t | j | j  } t    *} t | j d | d d } t! d | j
  } zyZ|  j" | | | |
 | |  t# | | j  |  j$ d | d
 | d | d | d |
 d | j  } |  j% d | d |
 d
 | d | d | j d | j d | j d | j& d | d | j'  
} |  j( |
  | j) |  y | j* d  } Wn t+ k
 rd  } n X| j, d  k } t- d |  t. |
 j  } g  | j/ j0   D] } t1 | |  r| ^ q} t2 | d | d g  d g  \ } } g  | D] } | j' rK| ^ qK} | rt3 d j4 d  j5 d!   | D     n  | j6 |  } | j7 o| j8 } | r|  j9 |  n  | j: } | j
 rt; } n  t< | | | d" | j d# | d$ | j	 d% | j= d& | d | j } t> d' | j d# | d" | j d$ | j	 d( | j  } t? j@ |  } | jA d) tB jC d*   g  }  xh | D]` }! |! jD }" y0 tE |! jD d+ | }# |# r|" d, |# 7}" n  Wn tF k
 rn X|  jG |"  qWd- j5 |   }$ |$ rtH d. |$  n  Wng tI k
 rk}% |  jJ d/ k }& tK |% |& | j  }' tL jM |' d0 |& tN StO k
 rt | _   n XWd  | j s| jP   | jQ   n  XWd  QXWd  QX| j
 r|  jR | j
 | | j  n  tS S(1   Ns   to-satisfy-onlyt   check_targetR=   R3   R<   t   isolated_modes=   Target path exists but is not a directory, will not continue.t   kindt   targett   optionst   sessiont   target_pythonRT   t   deletet   installt   check_supported_wheelst   temp_build_dirt   req_trackert   finderR8   t   preparert   wheel_cacheRC   RB   R?   R'   t   pipt   modifying_pipt   build_optionsRX   sP   Could not build wheels for {} which use PEP 517 and cannot be installed directlys   , c         s@  s   |  ] } | j  Vq d  S(   N(   R)   (   t   .0t   r(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pys	   <genexpr>w  s    t   roott   homet   prefixt	   pycompileRE   t   usert   isolatedt   keyR)   t   working_sett   -t    s   Successfully installed %si   t   exc_info(T   R   t   check_install_build_globalR>   R?   t   check_dist_restrictionR(   RW   t   decide_user_installR8   R=   R3   R<   Rh   RP   RC   t   ost   patht   abspatht   existst   isdirR
   R   RX   t   get_default_sessionR   t   _build_package_finderRT   R\   RR   R   t	   cache_dirR.   R   R   t   populate_requirement_sett   warn_deprecated_install_optionst   make_requirement_preparert   make_resolverRB   R'   t   trace_basic_infot   resolvet   get_requirementt   KeyErrort   satisfied_byR   R0   RK   t   valuesR   R   R   t   formatt   joint   get_installation_ordert   ignore_dependenciesRF   t   _warn_about_conflictsRE   t   FalseR   RD   t   get_lib_location_guessesR   t
   WorkingSett   sortt   operatort
   attrgetterR)   R   t	   Exceptiont   appendR   t   EnvironmentErrort	   verbosityt   create_env_error_messaget   loggert   errorR   R   t   cleanup_filest   cleanupt   _handle_target_dirR	   ((   Rc   Rk   Rd   R?   RW   t   target_temp_dirt   target_temp_dir_pathRX   Rl   Rm   Rs   t   build_deleteRu   Rr   t	   directoryt   requirement_setRt   t   resolvert   pip_reqRw   R/   Rz   t   reqs_to_buildt   _t   build_failurest   pep517_build_failurest
   to_installt   should_warn_about_conflictsRE   t	   installedt   lib_locationsR   t   itemst   resultt   itemt   installed_versiont   installed_descR   t   show_tracebackt   message(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   run   s$   								  						
	""	
													
	c      
   @  s  t  |  g  } | t d d | j } | d } | d } | d } t j j |  rl | j |  n  t j j |  r | | k r | j |  n  t j j |  r | j |  n  x.| D]&}	 xt j |	  D]}
 |	 | k r)t j j | |
    t   f d   | d  D  r)q q)n  t j j | |
  } t j j |  r| slt	 j
 d |  q n  t j j |  rt	 j
 d	 |  q n  t j j |  rt j |  qt j |  n  t j t j j |	 |
  |  q Wq WWd  QXd  S(
   Nt    R|   t   purelibt   platlibt   datac         3@  s   |  ] } | j     Vq d  S(   N(   t
   startswith(   Ry   t   s(   t   ddir(    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pys	   <genexpr>  s    isK   Target directory %s already exists. Specify --upgrade to force replacement.s   Target directory %s already exists and is a link. Pip will not automatically replace links, please remove if replacement is desired.(   R   R   R   R   R   R   t   listdirR   t   anyR   t   warningt   islinkR   t   shutilt   rmtreet   removet   move(   Rc   R3   R   R>   t   lib_dir_listt   schemet   purelib_dirt   platlib_dirt   data_dirt   lib_dirR   t   target_item_dir(    (   R   s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR     sJ    



 	c      	   C@  s   y t  |  \ } } Wn% t k
 r= t j d d t d  SX| \ } } xK | D]C } | | d } x, | | D]  } t j d | | | d  qp WqQ WxV | D]N } | | d } x7 | | D]+ \ }	 }
 } t j d | | | |	 |
  q Wq Wd  S(   Ns   Error checking for conflicts.R   i    s*   %s %s requires %s, which is not installed.i   sF   %s %s has requirement %s, but you'll have %s %s which is incompatible.(   R   R   R   R   R(   t   critical(   Rc   R   t   package_sett	   _dep_infot   missingt   conflictingt   project_namet   versiont
   dependencyt   dep_namet   dep_versionR+   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR     s$    (   t   __name__t
   __module__t   __doc__t   usageRH   R   R   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR1   J   s   			8c          O@  s$   t  d |  |  } | d | d g S(   NR   R   R   (   R   (   Rd   t   kwargsR   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR     s    c          K@  s    t  d   t t |     D  S(   Nc         s@  s   |  ] } t  |  Vq d  S(   N(   R   (   Ry   t   d(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pys	   <genexpr>%  s    (   t   allt   setR   (   R   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   site_packages_writable#  s    c         C@  s   |  d k	 r$ |  r$ t j d  t S|  rh | r? t d   n  t   rW t d   n  t j d  t S|  d k sz t  | s | r t j d  t St	 j
 s t j d  t St d | d |  r t j d	  t St j d
  t S(   sZ  Determine whether to do a user install based on the input options.

    If use_user_site is False, no additional checks are done.
    If use_user_site is True, it is checked for compatibility with other
    options.
    If use_user_site is None, the default behaviour depends on the environment,
    which is provided by the other arguments.
    s$   Non-user install by explicit requestsV   Can not combine '--user' and '--prefix' as they imply different installation locationssZ   Can not perform a '--user' install. User site-packages are not visible in this virtualenv.s    User install by explicit requests3   Non-user install due to --prefix or --target options4   Non-user install because user site-packages disabledR{   R   s0   Non-user install because site-packages writeablesM   Defaulting to user installation because normal site-packages is not writeableN(   RP   R   t   debugR   R
   R   R   R(   t   AssertionErrort   sitet   ENABLE_USER_SITER   t   info(   R8   R=   R3   R<   Rh   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR   )  s0    		c      	   C@  s
  d   } |  j  t |  j j    } g  } x] | D]U } | j j d g   } t |  } | r2 | j d j | | j	    |   q2 q2 W| r t |  } | r | j d j | | j	      q n  | s d St
 d d j d j |   d	 d
 d d d d  d S(   s   If any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    c         S@  s,   g  |  D]! } d j  | j d d   ^ q S(   Ns   --{}R   R   (   R   t   replace(   t   option_namesR)   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   format_optionsj  s    RW   s   {!r} from {}s   {!r} from command lineNt   reasons}   Location-changing options found in --install-option: {}. This configuration may cause unexpected behavior and is unsupported.s   ; t   replacementsC   using pip-level options like --user, --prefix, --root, and --targett   gone_ins   20.2t   issuei  (   t   unnamed_requirementst   listRK   R   Rk   t   getR   R   R   t   keysR   R   (   R   Rk   R   RK   t	   offenderst   requirementRW   t   location_options(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR   e  s2    	 c         C@  s   g  } | j  d  | s< | j  d  | j  t |    n | j  d  | d c d 7<|  j t j k r d } d } | s | j | d | j   g  n | j  |  | j  d	  n  d
 j |  j   d S(   s{   Format an error message for an EnvironmentError

    It may occur anytime during the execution of the install command.
    s5   Could not install packages due to an EnvironmentErrors   : t   .is   
s"   Consider using the `--user` options   Check the permissionss    or s   .
R   (   R   t   strt   errnot   EACCESt   extendt   lowerR   t   strip(   R   R   t   using_user_sitet   partst   user_option_partt   permissions_part(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyR     s"    (Q   t
   __future__R    R  t   loggingR   R   R   R   t   optparseR   t   pip._vendorR   t   pip._vendor.packaging.utilsR   t   pip._internal.cacheR   t   pip._internal.cliR   t   pip._internal.cli.cmdoptionsR   t   pip._internal.cli.req_commandR   t   pip._internal.cli.status_codesR   R	   t   pip._internal.exceptionsR
   R   R   t   pip._internal.locationsR   t   pip._internal.operations.checkR   t   pip._internal.reqR   R   t   pip._internal.req.req_trackerR   t   pip._internal.utils.deprecationR   t"   pip._internal.utils.distutils_argsR   t   pip._internal.utils.filesystemR   t   pip._internal.utils.miscR   R   R   R   t   pip._internal.utils.temp_dirR   t   pip._internal.utils.typingR   t   pip._internal.utils.virtualenvR   t   pip._internal.wheel_builderR   R   R   t   typingR   R    R!   R"   t#   pip._internal.models.format_controlR#   t   pip._internal.req.req_installR$   R%   t	   getLoggerR   R   R0   R1   R   R   RP   R   R   R   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/commands/install.pyt   <module>   sZ   ""	 		7	7