3

gf                 @   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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 e4rd dlm:Z: d dl;m<Z<m=Z=m>Z>m?Z? d dl@mAZA d dlBmCZC d dl7mDZD ejEeFZGdd ZHG dd  d eZId!d" ZJd#d$ ZKd,d&d'ZLd(d) ZMd*d+ ZNdS )-    )absolute_importN)SUPPRESS_HELP)pkg_resources)canonicalize_name)
WheelCache)
cmdoptions)make_target_python)RequirementCommand)ERRORSUCCESS)CommandErrorInstallationErrorPreviousBuildDirError)distutils_scheme)check_install_conflicts)RequirementSet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} j|}d|kS )NTbinary)
use_pep517r   nameget_allowed_formats)reqcanonical_nameallowed_formats)format_control B/tmp/pip-unpacked-wheel-v59g9nu1/pip/_internal/commands/install.pycheck_binary_allowed?   s
    

z6get_check_binary_allowed.<locals>.check_binary_allowedr0   )r/   r2   r0   )r/   r1   get_check_binary_allowed=   s    r3   c                   s<   e Zd ZdZdZ fddZ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                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 tj| |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 |jtj  |jtj  |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 |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) |jd*dd&d+d, |jd-dd.d'd/d) |jd0dd1d'd2d) |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 )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.))r7   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).)r7   r9   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=   r7   r9   r:   z--no-compilez.Do not compile Python source files to bytecode)r=   r7   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   )superr4   __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no_cleanrequire_hashesprogress_barmake_option_groupindex_groupparserinsert_option_group)selfargskwrL   
index_opts)	__class__r0   r1   rK   ^   s    
	zInstallCommand.__init__c       &   .      s
  t j| d}|jr|j}t j|dd |jp0g }t|j|j|j	|j
|jd|_d }d }|j	rd|_tjj|j	|_	tjj|j	rtjj|j	 rtdtdd}|j}|jpg }| j|}t|}	| j|||	|jd}
|jp|j }t|j|j}t }t|j|d	d
}t|j	 d}zy,| j ||||
|| t!||j | j"|||||
|jd}| j#||
|||j|j|j|j$||j%d
}| j&|
 |j'| y|j(d}W n t)k
r   d }Y nX |j*d k}t+|d t,|
j  fdd|j-j. D }t/||g g d\}}dd |D }|rDt0dj1dj2dd |D |j3|}|j4 o\|j5}|rn| j6| |j7}|j	rd}t8||||j
||j|j9||jd	}t:|j||j
|j|jd}t;j<|}|j=t>j?dd g }xZ|D ]R}|j@} y$tA|j@|d}!|!r| d|! 7 } W n tBk
r&   Y nX |jC|  qW dj2|}"|"rRtDd |" W nd tEk
r }# z*| jFd!k}$tG|#|$|j}%tHjI|%|$d" tJS d }#~#X n tKk
r   d|_ Y nX W d |js|jL  |jM  X W d Q R X W d Q R X |j	r| jN|j	||j tOS )#Nzto-satisfy-onlyT)check_target)r@   r5   r?   isolated_modez=Target path exists but is not a directory, will not continue.target)kind)optionssessiontarget_pythonrV   install)deleterm   )check_supported_wheels)temp_build_dirrn   req_trackerro   finderr;   )
preparerrv   rn   wheel_cacher;   rF   rV   rE   rB   r)   pip)modifying_pipc                s   g | ]}t | r|qS r0   )r   ).0r)r2   r0   r1   
<listcomp>^  s    z&InstallCommand.run.<locals>.<listcomp>)rx   build_optionsrZ   c             S   s   g | ]}|j r|qS r0   )r)   )r{   r|   r0   r0   r1   r}   q  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{   r|   r0   r0   r1   	<genexpr>w  s    z%InstallCommand.run.<locals>.<genexpr>F)roothomeprefix	pycompilerH   r;   )userr   r   r   isolatedr*   )key)working_set- zSuccessfully installed %s   )exc_info)Pr   check_install_build_globalrA   rB   check_dist_restrictionrY   decide_user_installr;   r@   r5   r?   rk   rF   ospathabspathexistsisdirr   r   rZ   get_default_sessionr   _build_package_finderrV   r^   rT   r   	cache_dirr/   r   r   populate_requirement_setwarn_deprecated_install_optionsmake_requirement_preparermake_resolverrE   r)   trace_basic_inforesolveget_requirementKeyErrorsatisfied_byr   r3   rN   valuesr   r   formatjoinget_installation_orderignore_dependenciesrI   _warn_about_conflictsrH   r   rG   get_lib_location_guessesr   
WorkingSetsortoperator
attrgetterr*   r   	Exceptionappendr   EnvironmentError	verbositycreate_env_error_messageloggererrorr
   r   cleanup_filescleanup_handle_target_dirr   )&re   rn   rf   rB   rY   target_temp_dirtarget_temp_dir_pathrZ   ro   rp   rv   build_deleterx   ru   	directoryrequirement_setrw   resolverpip_reqrz   reqs_to_build_build_failurespep517_build_failures
to_installshould_warn_about_conflictsrH   	installedlib_locationsr   itemsresultiteminstalled_versioninstalled_descr   show_tracebackmessager0   )r2   r1   run   s   













	







zInstallCommand.runc                sp  t | g }|T td|jd}|d }|d }|d }tjj|rP|j| tjj|rn||krn|j| tjj|r|j| x|D ]}	xtj|	D ]}
|	|krtjj||
 t fdd|d d D rqtjj||
}tjj|rD|st	j
d	| qtjj|r t	j
d
| qtjj|r:tj| n
tj| tjtjj|	|
| qW qW W d Q R X d S )N )r   purelibplatlibdatac             3   s   | ]}|j  V  qd S )N)
startswith)r{   s)ddirr0   r1   r     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)re   r5   r   rA   lib_dir_listschemepurelib_dirplatlib_dirdata_dirlib_dirr   target_item_dirr0   )r   r1   r     sJ    




z!InstallCommand._handle_target_dirc             C   s   yt |\}}W n" tk
r2   tjddd d S X |\}}x>|D ]6}|| d }x$|| D ]}tjd|||d  q\W qBW xD|D ]<}|| d }x*|| D ]\}	}
}tjd||||	|
 qW qW d S )NzError checking for conflicts.T)r   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)re   r   package_set	_dep_infomissingconflictingproject_nameversion
dependencydep_namedep_versionr,   r0   r0   r1   r     s$    

z$InstallCommand._warn_about_conflicts)
__name__
__module____qualname____doc__usagerK   r   r   r   __classcell__r0   r0   )ri   r1   r4   J   s     Z8r4   c              O   s   t d| |}|d |d gS )Nr   r   r   )r   )r   )rf   kwargsr   r0   r0   r1   r     s    r   c              K   s   t dd ttf | D S )Nc             s   s   | ]}t |V  qd S )N)r   )r{   dr0   r0   r1   r   %  s    z)site_packages_writable.<locals>.<genexpr>)allsetr   )r   r0   r0   r1   site_packages_writable#  s    r   Fc             C   s   | dk	r|  rt jd dS | rH|r,tdt r:tdt jd dS | dksTt|s\|rjt jd dS tjs~t jd	 dS t||d
rt jd dS t 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 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;   r@   r5   r?   rk   r0   r0   r1   r   )  s0    





r   c             C   s   dd }| j t| jj  }g }x@|D ]8}|jjdg }t|}|r&|jdj||j	 | q&W |rt|}|r|jdj||j	  |sdS t
djdj|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 j |jddqS )z--{}r   r   )r   replace)r{   r*   r0   r0   r1   r}   l  s    zKwarn_deprecated_install_options.<locals>.format_options.<locals>.<listcomp>r0   )option_namesr0   r0   r1   format_optionsj  s    z7warn_deprecated_install_options.<locals>.format_optionsrY   z{!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)unnamed_requirementslistrN   r   rn   getr   r   r   keysr   r   )r   rn   r   rN   	offendersrequirementrY   location_optionsr0   r0   r1   r   e  s2    

r   c             C   s   g }|j d |s,|j d |j t|  n
|j d |d  d7  < | jtjkrd}d}|st|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   
z"Consider using the `--user` optionzCheck the permissionsz or z.
r   r   )r   strerrnoEACCESextendlowerr   strip)r   r   using_user_sitepartsuser_option_partpermissions_partr0   r0   r1   r     s"    




r   )NNNF)O
__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	   pip._internal.cli.status_codesr
   r   pip._internal.exceptionsr   r   r   pip._internal.locationsr   pip._internal.operations.checkr   Zpip._internal.reqr   r   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   r3   r4   r   r   r   r   r   r0   r0   r0   r1   <module>   s^   
   W   
77