
(hk                 @   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 m Z d  d
 l m Z 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- m. Z. d  d l/ m0 Z0 d  d l1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 m7 Z7 e2 r:d  d l m8 Z8 d  d l9 m: Z: m; Z; m< Z< d  d l= m> Z> d  d l m? Z? d  d l@ mA ZA d  d l5 mB ZB e jC eD  ZE d d   ZF Gd d    d  e  ZG d! d d d! d d" d#  ZH d$ d%   ZI d d d d! d& d'  ZJ d( d)   ZK d* d+   ZL d S),    )absolute_importN)SUPPRESS_HELP)pkg_resources)canonicalize_name)
WheelCache)
cmdoptions)make_target_python)RequirementCommandwith_cleanup)ERRORSUCCESS)CommandErrorInstallationError)distutils_scheme)check_install_conflicts)install_given_reqs)get_requirement_tracker)parse_distutils_args)test_writable_dir)
ensure_dirget_installed_versionget_pip_version(protect_pip_from_modification_on_windowswrite_output)TempDirectory)MYPY_CHECK_RUNNING)virtualenv_no_global)build should_build_for_install_command)Values)IterableListOptional)FormatControl)ConflictDetails)InstallRequirement)BinaryAllowedPredicatec                s     f d d   } | S)Nc                s5   |  j  r d St |  j  }   j |  } d | k S)NTbinary)
use_pep517r   nameZget_allowed_formats)reqcanonical_nameZallowed_formats)format_control =/tmp/pip-build-kmztzv_d/pip/pip/_internal/commands/install.pycheck_binary_allowed5   s
    	z6get_check_binary_allowed.<locals>.check_binary_allowedr-   )r,   r/   r-   )r,   r.   get_check_binary_allowed3   s    r0   c               @   s^   e  Z d  Z d Z d Z d d   Z e d d    Z d d   Z d	 d
   Z	 d d   Z
 d S)InstallCommandaI  
    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.
    a%  
      %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             C   s  |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j d d d d d d d d  d d	 t j |  j   |  j  j d
 d d d d d d |  j  j d d d d d d t	 |  j  j d d d d d d d  d d |  j  j d d d d d d d  d d |  j  j t j
    |  j  j t j    |  j  j d d d d d d d d |  j  j d d d d d d d d g d d  |  j  j d! d d" d d d d# |  j  j d$ d% d d& d d d d' |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j d( d d d d) d d* d d+ |  j  j d, d d d d) d d- |  j  j d. d d d d/ d d* d d0 |  j  j d1 d d d d2 d d* d d3 |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    |  j  j t j    t j t j |  j  } |  j j d4 |  |  j j d4 |  j   d  S)5Nz-tz--targetdest
target_dirmetavardirdefaulthelpzInstall 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.z--useruse_user_siteaction
store_truezInstall 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.)z	--no-userstore_falsez--root	root_pathz=Install everything relative to this alternate root directory.z--prefixprefix_pathzIInstallation prefix where lib, bin and other top-level folders are placedz-Uz	--upgradeupgradezUpgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.z--upgrade-strategyupgrade_strategyzonly-if-neededchoicesZeageraG  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).z--force-reinstallforce_reinstallz;Reinstall all packages even if they are already up-to-date.z-Iz--ignore-installedignore_installedzIgnore 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!z	--compilecompileTz'Compile Python source files to bytecodez--no-compilez.Do not compile Python source files to bytecodez--no-warn-script-locationwarn_script_locationz0Do not warn when installing scripts outside PATHz--no-warn-conflictswarn_about_conflictsz%Do not warn about broken dependenciesr   )cmd_opts
add_optionr   requirementsconstraintsno_depspreeditableZadd_target_python_optionsr   	build_dirsrcignore_requires_pythonZno_build_isolationr(   Zno_use_pep517install_optionsglobal_options	no_binaryonly_binaryZprefer_binaryrequire_hashesZprogress_barmake_option_groupindex_groupparserinsert_option_group)self
index_optsr-   r-   r.   add_optionsT   s    																	zInstallCommand.add_optionsc       (         s  | j  r$ | j d  k	 r$ t d   t j |  d } | j rI | j } t j | d d | j ph g  } t	 j
 d t    t | j  d | j d | j d | j d	 | j | _  d  } d  } | j rFd | _ t j j | j  | _ t j j | j  r!t j j | j  r!t d
   t d d  } | j } |  j |  | j pRg  } |  j |  } t |  }	 |  j d | d | d |	 d | j  }
 t | j | j  } |  j t     } t d | j! d d d d  } y|  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) | d | j } y | j* d  } Wn t+ k
 rd  } Yn X| j, d  k } t- d! |  t. |
 j      f d" d#   | j/ j0   D } t1 | d | d$ d d% g  d& g  \ } } d' d#   | D } | rt2 d( j3 d) j4 |     x  | D] } | j' sd* | _5 qW| j6 |  } d  } | j7 o| j8 } | r|  j9 |  } | j: } | j rd  } t; | | | d+ | j d, | d- | j d. | d | j  d/ | j< } t= d0 | j  d, | d+ | j d- | j d1 | j  } t> j? |  } | j@ d2 tA jB d3   g  }  xf | D]^ }! |! jC }" y- tD |! jC d4 | }# |# r|" d5 |# 7}" Wn tE k
 rYn X|  jF |"  qW| d  k	 r@|  jG | d6 |  jH |  d7 j4 |   }$ |$ rbtI d8 |$  Wn` tJ k
 r}% z@ |  jK d9 k }& tL |% |& | j   }' t	 jM |' d: |& tN SWYd  d  }% ~% Xn X| j r| stO  |  jP | j | | j  tQ S);Nz'Can not combine '--user' and '--target'zto-satisfy-onlyZcheck_targetTzUsing %sr=   r3   r<   isolated_modez=Target path exists but is not a directory, will not continue.kindtargetoptionssessiontarget_pythonrO   deleteinstallZglobally_managedZtemp_build_dirreq_trackerfinderr8   preparerwheel_cacherB   rA   r?   r(   Zcheck_supported_wheelspipFmodifying_pipc                s%   g  |  ] } t  |    r |  q Sr-   )r   ).0r)r/   r-   r.   
<listcomp>U  s   	 z&InstallCommand.run.<locals>.<listcomp>verifybuild_optionsrQ   c             S   s"   g  |  ] } | j  r | j  q Sr-   )r(   r)   )rj   rk   r-   r-   r.   rl   f  s   	zPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, i   roothomeprefixrD   	pycompileuserisolatedkeyr)   working_set-resolver_variant zSuccessfully installed %s   exc_info)Rr8   r3   r   r   check_install_build_globalr>   r?   Zcheck_dist_restrictionrP   loggerdebugr   decide_user_installr=   r<   r\   rB   ospathabspathexistsisdirr   enter_contextrQ   Zget_default_sessionr   _build_package_finderrO   r   	cache_dirr,   r   no_cleanZget_requirements'reject_location_related_install_optionsZmake_requirement_preparerZmake_resolverrA   r(   Ztrace_basic_inforesolveget_requirementKeyErrorsatisfied_byr   r0   rH   valuesr   r   formatjoinZlegacy_install_reasonZget_installation_orderignore_dependenciesrE   _determine_conflictsrD   r   rC   get_lib_location_guessesr   
WorkingSetsortoperator
attrgetterr)   r   	Exceptionappend_warn_about_conflictsZdetermine_resolver_variantr   EnvironmentError	verbositycreate_env_error_messageerrorr   AssertionError_handle_target_dirr   )(rY   r_   argsr?   rP   target_temp_dirZtarget_temp_dir_pathrQ   r`   ra   re   rg   rd   	directoryreqsrf   resolverrequirement_setZpip_reqri   Zreqs_to_build_Zbuild_failuresZpep517_build_failure_namesrk   
to_installZ	conflictsZshould_warn_about_conflictsrD   	installedZlib_locationsrv   itemsresultiteminstalled_versionZinstalled_descr   show_tracebackmessager-   )r/   r.   run   s*   											
							"	
		
											zInstallCommand.runc                s  t  |  g  } t d d | j } | d } | d } | d } t j j |  rb | j |  t j j |  r | | k r | j |  t j j |  r | j |  x(| D] }	 xt j |	  D]}
 |	 | k rt j j | |
    t   f d d   | d  d  D  rq t j j | |
  } t j j |  r| s\t	 j
 d	 |  q t j j |  rt	 j
 d
 |  q t j j |  rt j |  n t j |  t j t j j |	 |
  |  q Wq Wd  S)N rp   purelibplatlibdatac             3   s   |  ] } | j     Vq d  S)N)
startswith)rj   s)ddirr-   r.   	<genexpr>  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>rz   zKTarget directory %s already exists. Specify --upgrade to force replacement.zTarget 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   listdirr   anyr}   warningislinkr   shutilrmtreeremovemove)rY   r3   r   r>   Zlib_dir_listschemeZpurelib_dirZplatlib_dirZdata_dirlib_dirr   target_item_dirr-   )r   r.   r     sH    



)z!InstallCommand._handle_target_dirc             C   s8   y t  |  SWn# t k
 r3 t j d  d  SYn Xd  S)NzwError while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new)r   r   r}   	exception)rY   r   r-   r-   r.   r     s    z#InstallCommand._determine_conflictsc             C   sn  | \ } \ } } | r$ | r$ d  Sg  } | d k rF | j  d  n | d k sX t  | j  d  x` | D]X } | | d } xA | | D]5 }	 d j d | d | d	 |	 d
  }
 | j  |
  q Wql Wx | D] } | | d } xj | | D]^ \ } } } d j d | d | d	 | d | d | d | d k r6d n d  }
 | j  |
  q Wq Wt j d j |   d  S)Nlegacyzpip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.z2020-resolverzpip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.r   z@{name} {version} requires {requirement}, which is not installed.r)   versionrequirementrz   zg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.dep_namedep_versionZyouzyou'll
)r   r   r   r}   criticalr   )rY   Zconflict_detailsrx   Zpackage_setmissingZconflictingpartsproject_namer   
dependencyr   r   r   r*   r-   r-   r.   r     s<    
		z$InstallCommand._warn_about_conflictsN)__name__
__module____qualname____doc__usager[   r
   r   r   r   r   r-   r-   r-   r.   r1   @   s   8r1   Fc             C   s<   t  d d |  d | d | d | d | } | d | d g S)	Nr   rs   rp   ro   rt   rq   r   r   )r   )rs   rp   ro   rt   rq   r   r-   r-   r.   r   D  s    r   c             C   s,   t  d d   t t d |  d |   D  S)Nc             s   s   |  ] } t  |  Vq d  S)N)r   )rj   dr-   r-   r.   r   T  s    z)site_packages_writable.<locals>.<genexpr>ro   rt   )allsetr   )ro   rt   r-   r-   r.   site_packages_writableQ  s    r   c             C   s   |  d k	 r$ |  r$ t  j d  d S|  rb | r< t d   t   rQ t d   t  j d  d S|  d k st t  | s | r t  j d  d St j s t  j d	  d St d
 | d |  r t  j d  d St  j	 d  d S)aZ  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.
    Nz$Non-user install by explicit requestFzVCan not combine '--user' and '--prefix' as they imply different installation locationszZCan not perform a '--user' install. User site-packages are not visible in this virtualenv.z User install by explicit requestTz3Non-user install due to --prefix or --target optionz4Non-user install because user site-packages disabledro   rt   z0Non-user install because site-packages writeablezMDefaulting to user installation because normal site-packages is not writeable)
r}   r~   r   r   r   r   siteENABLE_USER_SITEr   info)r8   r=   r3   r<   r\   r-   r-   r.   r   Y  s0    				r   c             C   s   d d   } g  } xN |  D]F } | j  } t |  } | r | j d j | | j    |   q W| r t |  } | r | j d j | | j      | s d St d j d j |     d S)zIf any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    c             S   s   d d   |  D S)Nc             S   s+   g  |  ]! } d  j  | j d d    q S)z--{}r   rw   )r   replace)rj   r)   r-   r-   r.   rl     s   	 zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r-   )Zoption_namesr-   r-   r.   format_options  s    z?reject_location_related_install_options.<locals>.format_optionsz{!r} from {}z{!r} from command lineNzLocation-changing options found in --install-option: {}. This is unsupported, use pip-level options like --user, --prefix, --root, and --target instead.z; )rP   r   r   r   keysr   r   )rH   r_   r   Z	offendersr   rP   Zlocation_optionsr-   r-   r.   r     s(    	r   c             C   s   g  } | j  d  | s< | j  d  | j  t |    n | j  d  | d d 7<|  j t j k r d } d } | s | j | d | j   g  n | j  |  | j  d	  d
 j |  j   d S)z{Format an error message for an EnvironmentError

    It may occur anytime during the execution of the install command.
    z5Could not install packages due to an EnvironmentErrorz: .rz   r   z"Consider using the `--user` optionzCheck the permissionsz or z.
r   r   )r   strerrnoZEACCESextendlowerr   strip)r   r   Zusing_user_siter   Zuser_option_partZpermissions_partr-   r-   r.   r     s"    r   )M
__future__r   r   loggingr   r   r   r   optparser   Zpip._vendorr   pip._vendor.packaging.utilsr   Zpip._internal.cacher   Zpip._internal.clir   Zpip._internal.cli.cmdoptionsr   Zpip._internal.cli.req_commandr	   r
   Zpip._internal.cli.status_codesr   r   Zpip._internal.exceptionsr   r   Zpip._internal.locationsr   Zpip._internal.operations.checkr   Zpip._internal.reqr   Zpip._internal.req.req_trackerr   Z"pip._internal.utils.distutils_argsr   Zpip._internal.utils.filesystemr   Zpip._internal.utils.miscr   r   r   r   r   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr   Zpip._internal.utils.virtualenvr   Zpip._internal.wheel_builderr   r   r   Ztypingr    r!   r"   Z#pip._internal.models.format_controlr#   r$   Zpip._internal.req.req_installr%   r&   	getLoggerr   r}   r0   r1   r   r   r   r   r   r-   r-   r-   r.   <module>   sd   (  
7*