
0c@_p                 @   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* d  d l+ m, Z, d  d l- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 d  d l9 m: Z: m; Z; e6 rZd  d l m< Z< d  d l= m> Z> m? Z? m@ Z@ d  d lA mB ZB d  d l mC ZC d  d lD mE ZE d  d l9 mF ZF e jG eH  ZI d d    ZJ Gd! d"   d" e  ZK d# d d d# d d$ d%  ZL d& d'   ZM d d d d# d( d)  ZN d* d+   ZO d, d-   ZP 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)today_is_later_than)
deprecated)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-jynh7p1z/pip/pip/_internal/commands/install.pycheck_binary_allowed7   s
    	z6get_check_binary_allowed.<locals>.check_binary_allowedr/   )r.   r1   r/   )r.   r0   get_check_binary_allowed5   s    r2   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/   r0   add_optionsV   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  }
 | j p| j } t | j  | j!  } |  j t"    } t | j d | 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#   | j0 j1   D } t2 | d | d$ g  d% g  \ } } d& d#   | D } | rt3 d' j4 d( j5 |     d) d#   | D } | rt6 d* d+ j4 d( j5 |   d, d- d. d/ d0 d1  | j7 |  } d  } | j8 o| j9 } | r*|  j: |  } | j; } | j rBd  } t< | | | d2 | j d3 | d4 | j d5 | d | j  d6 | j= } t> d7 | j  d3 | d2 | j d4 | j d8 | j  } t? j@ |  }  | jA d9 tB jC d:   g  }! xf | D]^ }" |" jD }# y- tE |" jD d; |  }$ |$ r'|# d< |$ 7}# Wn tF k
 r<Yn X|! jG |#  qW| d  k	 rv|  jH | d= d> | jI k d? j5 |!  }% |% rtJ d@ |%  Wn` tK k
 r}& z@ |  jL dA k }' tM |& |' | j   }( t	 jN |( dB |' tO SWYd  d  }& ~& Xn X| j r*| stP  |  jQ | j | | j  tR S)CNz'Can not combine '--user' and '--target'zto-satisfy-onlyZcheck_targetTzUsing %sr?   r5   r>   isolated_modez=Target path exists but is not a directory, will not continue.kindtargetoptionssessiontarget_pythonrQ   deleteinstallZglobally_managedZtemp_build_dirreq_trackerfinderr:   preparerwheel_cacherD   rC   rA   r*   Zcheck_supported_wheelspipFmodifying_pipc                s%   g  |  ] } t  |    r |  q Sr/   )r    ).0r)r1   r/   r0   
<listcomp>Y  s   	 z&InstallCommand.run.<locals>.<listcomp>build_optionsrS   c             S   s"   g  |  ] } | j  r | j  q Sr/   )r*   r+   )rl   rm   r/   r/   r0   rn   i  s   	zPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, c             S   s"   g  |  ] } | j  s | j  q Sr/   )r*   r+   )rl   rm   r/   r/   r0   rn   x  s   	reasonzrCould not build wheels for {} which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these.replacementz+to fix the wheel build issue reported aboveZgone_inz21.0Zissuei   roothomeprefixrF   	pycompileuserisolatedkeyr+   working_set-new_resolverz2020-resolver zSuccessfully installed %s   exc_info)Sr:   r5   r   r   check_install_build_globalr@   rA   Zcheck_dist_restrictionrR   loggerdebugr   decide_user_installr?   r>   r^   rD   ospathabspathexistsisdirr   enter_contextrS   Zget_default_sessionr   _build_package_finderrQ   no_cleanrO   r   	cache_dirr.   r   Zget_requirements'reject_location_related_install_optionsZmake_requirement_preparerZmake_resolverrC   r*   Ztrace_basic_inforesolveget_requirementKeyErrorsatisfied_byr   r2   rJ   valuesr   r   formatjoinr   Zget_installation_orderignore_dependenciesrG   _determine_conflictsrF   r   rE   get_lib_location_guessesr   
WorkingSetsortoperator
attrgetterr+   r   	Exceptionappend_warn_about_conflictsZfeatures_enabledr   EnvironmentError	verbositycreate_env_error_messageerrorr   AssertionError_handle_target_dirr   ))r[   ra   argsrA   rR   target_temp_dirZtarget_temp_dir_pathrS   rb   rc   rg   build_deleteri   rf   	directoryreqsrh   resolverrequirement_setZpip_reqrk   Zreqs_to_build_Zbuild_failuresZpep517_build_failure_namesZlegacy_build_failure_names
to_installZ	conflictsZshould_warn_about_conflictsrF   	installedZlib_locationsry   itemsresultiteminstalled_versionZinstalled_descr   show_tracebackmessager/   )r1   r0   run   s8   																			"	
	
	
											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 rs   purelibplatlibdatac             3   s   |  ] } | j     Vq d  S)N)
startswith)rl   s)ddirr/   r0   	<genexpr>  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>r}   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)r[   r5   r   r@   Zlib_dir_listschemeZpurelib_dirZplatlib_dirZdata_dirlib_dirr   target_item_dirr/   )r   r0   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)r[   r   r/   r/   r0   r     s    z#InstallCommand._determine_conflictsc             C   s  | \ } \ } } | r$ | r$ d  Sg  } | sM | j  d  | j  d  nD t d d d d d d  s | j  d	  d
 } | j  d j |   x` | D]X } | | d }	 xA | | D]5 }
 d j d | d |	 d |
 d  } | j  |  q Wq Wxq | D]i } | | d }	 xR | | D]F \ } } } d j d | d |	 d | d | d |  } | j  |  qWq Wt j d j |   d  S)NzAfter October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
z|We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
yeari  month   day   zPip will install or upgrade your package(s) and its dependencies without taking into account other packages you already have installed. This may cause an uncaught dependency conflict.
z#https://forms.gle/cWKMoDs8sUVE29hz9zXIf you would like pip to take your other packages into account, please tell us here: {}
r   z@{name} {version} requires {requirement}, which is not installed.r+   versionrequirementr}   zh{name} {version} requires {requirement}, but you'll have {dep_name} {dep_version} which is incompatible.dep_namedep_version
)r   r   r   r   criticalr   )r[   Zconflict_detailsr{   Zpackage_setmissingZconflictingpartsZ	form_linkproject_namer   
dependencyr   r   r   r,   r/   r/   r0   r     sF    

			z$InstallCommand._warn_about_conflictsN)__name__
__module____qualname____doc__usager]   r
   r   r   r   r   r/   r/   r/   r0   r3   B   s   8r3   Fc             C   s<   t  d d |  d | d | d | d | } | d | d g S)	Nr   rv   rs   rr   rw   rt   r   r   )r   )rv   rs   rr   rw   rt   r   r/   r/   r0   r   _  s    r   c             C   s,   t  d d   t t d |  d |   D  S)Nc             s   s   |  ] } t  |  Vq d  S)N)r   )rl   dr/   r/   r0   r   o  s    z)site_packages_writable.<locals>.<genexpr>rr   rw   )allsetr   )rr   rw   r/   r/   r0   site_packages_writablel  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 disabledrr   rw   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)r:   r?   r5   r>   r^   r/   r/   r0   r   t  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   rz   )r   replace)rl   r+   r/   r/   r0   rn     s   	 zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r/   )Zoption_namesr/   r/   r0   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; )rR   r   r   r   keysr   r   )rJ   ra   r   Z	offendersr   rR   Zlocation_optionsr/   r/   r0   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: .r}   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/   r0   r     s"    r   )Q
__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.datetimer   Zpip._internal.utils.deprecationr   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   r2   r3   r   r   r   r   r   r/   r/   r/   r0   <module>   sh   (   
7*