U
    Zޫ^Vc                     @   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,m-Z-m.Z.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8 e3rd dlm9Z9 d dl:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAmBZB d dl6mCZC eDeEZFdd ZGG dd  d eZHd!d" ZId#d$ ZJd,d&d'ZKd(d) ZLd*d+ ZMd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)
deprecated)parse_distutils_argstest_writable_dir)
ensure_dirget_installed_version(protect_pip_from_modification_on_windowswrite_output)TempDirectory)MYPY_CHECK_RUNNING)virtualenv_no_global)build should_build_for_install_command)Values)AnyIterableListOptional)FormatControl)InstallRequirement)BinaryAllowedPredicatec                    s    fdd}|S )Nc                    s&   | j r
dS t| j} |}d|kS )NTbinary)
use_pep517r   nameget_allowed_formats)reqcanonical_nameallowed_formatsformat_control B/tmp/pip-unpacked-wheel-huh_82lg/pip/_internal/commands/install.pycheck_binary_allowed;   s
    

z6get_check_binary_allowed.<locals>.check_binary_allowedr2   )r1   r4   r2   r0   r3   get_check_binary_allowed9   s    r5   c                       s@   e Zd ZdZdZ fddZedd Zdd Zd	d
 Z	  Z
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                    sP  t t| j|| | j}|t  |t  |t  |t	  |t
  |jddddd dd t| |jddd	d
d |jdddtd |jdddd dd |jdddd dd |t  |t  |jdddd	dd |jdddddgdd |jddd	d d |jd!d"d#d	d$d |t  |t  |t  |t  |t  |t  |jd%d	d&d'd(d) |jd*dd&d+d, |jd-dd.d'd/d) |jd0dd1d'd2d) |t  |t  |t  |t  |t  ttj| j}| jd3| | jd3| d S )4Nz-tz--target
target_dirdirzInstall 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.)destmetavardefaulthelpz--useruse_user_site
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.))r9   actionr<   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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).)r9   r;   choicesr<   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 bytecode)r?   r9   r;   r<   z--no-compilez.Do not compile Python source files to bytecode)r?   r9   r<   z--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   )superr6   __init__cmd_opts
add_optionr   requirementsconstraintsno_depspreeditableadd_target_python_optionsr   	build_dirsrcignore_requires_pythonno_build_isolationr*   no_use_pep517install_optionsglobal_options	no_binaryonly_binaryprefer_binaryrequire_hashesprogress_barmake_option_groupindex_groupparserinsert_option_group)selfargskwrN   
index_opts	__class__r2   r3   rM   Z   s     

 	 
zInstallCommand.__init__c           '         s  |j r|jd k	rtdt| d}|jr2|j}tj|dd |jpHg }t	|j |j
|j|j|jd|_ d }d }|jrd|_tj|j|_tj|jrtj|jstdtdd}|j}|jpg }| |}t|}	| j|||	|jd	}
|jp|j }t|j|j}| t }t|j|d
dd}z4| j |||
||j d}t!||j | j"|||||
|j d}| j#||
|||j |j|j|j$||j%d
}| &|
 |j'||j d}z|(d}W n t)k
r   d }Y nX |j*d k}t+|d t,|
j  fdd|j-. D }t/||g g d\}}dd |D }|rTt0d1d2dd |D |3|}|j4 ol|j5}|r~| 6| |j7}|jrd}t8||||j||j
|j9||j d	}t:|j ||j|j
|jd}t;<|}|j=t>?dd g }|D ]R} | j@}!z$tA| j@|d}"|"r|!d|" 7 }!W n tBk
r4   Y nX |C|! qd 2|}#|#r^tDd!|# W nR tEk
r }$ z2| jFd"k}%tG|$|%|j }&tHjI|&|%d# tJ W Y S d }$~$X Y nX |jr| K|j||j tLS )$Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)check_target)rB   r7   rA   isolated_modez=Target path exists but is not a directory, will not continue.target)kind)optionssessiontarget_pythonrX   install)deletero   globally_managed)check_supported_wheels)temp_build_dirrp   req_trackerrq   finderr=   )
preparerry   rp   wheel_cacher=   rH   rX   rG   rD   r*   pip)modifying_pipc                    s   g | ]}t | r|qS r2   )r    .0rr4   r2   r3   
<listcomp>`  s    z&InstallCommand.run.<locals>.<listcomp>)r{   build_optionsr\   c                 S   s   g | ]}|j r|qS r2   )r*   r~   r2   r2   r3   r   s  s     zPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, c                 s   s   | ]}|j V  qd S N)r+   r~   r2   r2   r3   	<genexpr>z  s     z%InstallCommand.run.<locals>.<genexpr>F)roothomeprefix	pycompilerJ   r=   )userr   r   r   isolatedr+   )key)working_set- zSuccessfully installed %s   exc_info)Mr=   r7   r   r   check_install_build_globalrC   rD   check_dist_restrictionr[   decide_user_installrB   rA   rm   rH   ospathabspathexistsisdirr   r\   get_default_sessionr   _build_package_finderrX   no_cleanrV   r   	cache_dirr1   enter_contextr   Zget_requirementswarn_deprecated_install_optionsmake_requirement_preparermake_resolverrG   r*   trace_basic_inforesolveget_requirementKeyErrorsatisfied_byr   r5   rP   valuesr   r   formatjoinget_installation_orderignore_dependenciesrK   _warn_about_conflictsrJ   r   rI   get_lib_location_guessesr   
WorkingSetsortoperator
attrgetterr+   r   	Exceptionappendr   EnvironmentError	verbositycreate_env_error_messageloggererrorr   _handle_target_dirr   )'rf   rp   rg   rD   r[   target_temp_dirtarget_temp_dir_pathr\   rq   rr   ry   build_deleter{   rx   	directoryreqsrz   resolverrequirement_setpip_reqr}   reqs_to_build_build_failurespep517_build_failures
to_installshould_warn_about_conflictsrJ   	installedlib_locationsr   itemsresultiteminstalled_versioninstalled_descr   show_tracebackmessager2   r   r3   run   sd   




    
 






 
 
    zInstallCommand.runc              	      sf  t | g }|J td|jd}|d }|d }|d }tj|rP|| tj|rn||krn|| tj|r|| |D ]}	t|	D ]}
|	|krtj||
 t fdd|d d D rqtj||
}tj|r>|st	
d	| qtj|rt	
d
| qtj|r4t| n
t| ttj|	|
| qqW 5 Q R X d S )N )r   purelibplatlibdatac                 3   s   | ]}|  V  qd S r   )
startswith)r   sddirr2   r3   r     s     z4InstallCommand._handle_target_dir.<locals>.<genexpr>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)rf   r7   r   rC   lib_dir_listschemepurelib_dirplatlib_dirdata_dirlib_dirr   target_item_dirr2   r   r3   r     sP    



z!InstallCommand._handle_target_dirc              
   C   s   zt |\}}W n$ tk
r4   tjddd Y d S X |\}}|D ]2}|| d }|| D ]}td|||d  qZqB|D ]8}|| d }|| D ]\}	}
}td||||	|
 qqzd S )NzError checking for conflicts.Tr   r   z*%s %s requires %s, which is not installed.r   zF%s %s has requirement %s, but you'll have %s %s which is incompatible.)r   r   r   r   critical)rf   r   package_set	_dep_infomissingconflictingproject_nameversion
dependencydep_namedep_versionr-   r2   r2   r3   r     s4          z$InstallCommand._warn_about_conflicts)__name__
__module____qualname____doc__usagerM   r
   r   r   r   __classcell__r2   r2   rj   r3   r6   F   s    
 Y8r6   c                  O   s   t d| |}|d |d gS )Nr   r   r   )r   r   )rg   kwargsr   r2   r2   r3   r     s    r   c                  K   s   t dd ttf | D S )Nc                 s   s   | ]}t |V  qd S r   r   )r   dr2   r2   r3   r     s    z)site_packages_writable.<locals>.<genexpr>)allsetr   )r   r2   r2   r3   site_packages_writable  s    r   Fc                 C   s   | dk	r| st d dS | rF|r*tdt r8tdt d dS | dksRt|sZ|rht d dS tjs|t d	 dS t||d
rt d dS t 	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 disabled)r   r   z0Non-user install because site-packages writeablezMDefaulting to user installation because normal site-packages is not writeable)
r   debugr   r   r   AssertionErrorsiteENABLE_USER_SITEr   info)r=   rB   r7   rA   rm   r2   r2   r3   r   $  s4    





r   c                 C   s   dd }g }| D ]0}|j }t|}|r|d|| | q|rjt|}|rj|d||  |srdS tdd|dd	d
d 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  |ddqS )z--{}r   r   )r   replace)r   r+   r2   r2   r3   r   g  s     zKwarn_deprecated_install_options.<locals>.format_options.<locals>.<listcomp>r2   )option_namesr2   r2   r3   format_optionse  s    z7warn_deprecated_install_options.<locals>.format_optionsz{!r} from {}z{!r} from command lineNz}Location-changing options found in --install-option: {}. This configuration may cause unexpected behavior and is unsupported.z; zCusing pip-level options like --user, --prefix, --root, and --targetz20.2i  )reasonreplacementgone_inissue)r[   r   r   r   keysr   r   )rP   rp   r  	offendersrequirementr[   location_optionsr2   r2   r3   r   `  s<    
 
r   c                 C   s   g }| d |s,| d | t|  n
| d |d  d7  < | jtjkrd}d}|st||d| g n
| | | d	 d
| 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   
z"Consider using the `--user` optionzCheck the permissionsz or z.
r   )r   strerrnoEACCESextendlowerr   strip)r   r   using_user_sitepartsuser_option_partpermissions_partr2   r2   r3   r     s&    


 

r   )NNNF)N
__future__r   r  loggingr   r   r   r  optparser   pip._vendorr   pip._vendor.packaging.utilsr   pip._internal.cacher   Zpip._internal.clir   Zpip._internal.cli.cmdoptionsr   pip._internal.cli.req_commandr	   r
   pip._internal.cli.status_codesr   r   pip._internal.exceptionsr   r   pip._internal.locationsr   pip._internal.operations.checkr   Zpip._internal.reqr   pip._internal.req.req_trackerr   pip._internal.utils.deprecationr   "pip._internal.utils.distutils_argsr   pip._internal.utils.filesystemr   pip._internal.utils.miscr   r   r   r   pip._internal.utils.temp_dirr   pip._internal.utils.typingr   pip._internal.utils.virtualenvr   pip._internal.wheel_builderr   r    r!   typingr"   r#   r$   r%   #pip._internal.models.format_controlr&   pip._internal.req.req_installr'   r(   	getLoggerr   r   r5   r6   r   r   r   r   r   r2   r2   r2   r3   <module>   s`   
   V    
<2