B
    `’»dVc  ã               @   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r¢d 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-hu9qqap1/pip/_internal/commands/install.pyÚcheck_binary_allowed;   s
    

z6get_check_binary_allowed.<locals>.check_binary_allowedr/   )r.   r1   r/   )r.   r0   Úget_check_binary_allowed9   s    r2   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Údirz¥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.)ÚdestÚmetavarÚdefaultÚhelpz--userÚuse_user_siteÚ
store_truez¸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.))r6   Úactionr9   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Úupgradez‚Upgrade 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).)r6   r8   Úchoicesr9   z--force-reinstallÚforce_reinstallz;Reinstall all packages even if they are already up-to-date.z-Iz--ignore-installedÚignore_installedz°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!z	--compileÚcompileTz'Compile Python source files to bytecode)r<   r6   r8   r9   z--no-compilez.Do not compile Python source files to bytecode)r<   r6   r9   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   )Úsuperr3   Ú__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ÚkwrK   Ú
index_opts)Ú	__class__r/   r0   rJ   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rÀd|_tj |j¡|_tj |j¡r°tj |j¡s°tdƒ‚tdd}|j}|jpÈg }|  |¡}t|ƒ}	| j|||	|jd	}
|jpú|j }t|j|jƒ}|  tƒ ¡}t|j|d
dd}y8| j |||
||j d}t!||jƒ | j"|||||
|j d}| j#||
|||j |j|j|j$||j%d
}|  &|
¡ |j'||j d}y| (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 }xZ|D ]R} | j@}!y$tA| j@|d}"|"r|!d|" 7 }!W n tBk
r6   Y nX | C|!¡ qòW d  2|¡}#|#rbtDd!|#ƒ W nJ tEk
r® }$ z*| jFd"k}%tG|$|%|j ƒ}&tHjI|&|%d# tJS d }$~$X Y nX |jrÊ|  K|j||j¡ tLS )$Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Úcheck_target)r?   r4   r>   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)ÚoptionsÚsessionÚtarget_pythonrU   Úinstall)Údeleterk   Úglobally_managed)Úcheck_supported_wheels)Útemp_build_dirrl   Úreq_trackerrm   Úfinderr:   )
Úpreparerru   rl   Úwheel_cacher:   rE   rU   rD   rA   r(   Úpip)Úmodifying_pipc                s   g | ]}t |ˆ ƒr|‘qS r/   )r   )Ú.0Úr)r1   r/   r0   ú
<listcomp>a  s    z&InstallCommand.run.<locals>.<listcomp>)rw   Úbuild_optionsrY   c             S   s   g | ]}|j r|‘qS r/   )r(   )rz   r{   r/   r/   r0   r|   t  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)   )rz   r{   r/   r/   r0   ú	<genexpr>z  s    z%InstallCommand.run.<locals>.<genexpr>F)ÚrootÚhomeÚprefixÚ	pycompilerG   r:   )Úuserr€   r   r   Úisolatedr)   )Úkey)Úworking_setú-ú zSuccessfully installed %sé   )Úexc_info)Mr:   r4   r   r   Úcheck_install_build_globalr@   rA   Úcheck_dist_restrictionrX   Údecide_user_installr?   r>   ri   rE   ÚosÚpathÚabspathÚexistsÚisdirr   rY   Úget_default_sessionr   Ú_build_package_finderrU   Úno_cleanrS   r   Ú	cache_dirr.   Úenter_contextr   Úget_requirementsÚwarn_deprecated_install_optionsÚmake_requirement_preparerÚmake_resolverrD   r(   Útrace_basic_infoÚresolveÚget_requirementÚKeyErrorÚsatisfied_byr   r2   rM   Úvaluesr   r   ÚformatÚjoinÚget_installation_orderÚignore_dependenciesrH   Ú_warn_about_conflictsrG   r   rF   Úget_lib_location_guessesr   Ú
WorkingSetÚsortÚoperatorÚ
attrgetterr)   r   Ú	ExceptionÚappendr   ÚEnvironmentErrorÚ	verbosityÚcreate_env_error_messageÚloggerÚerrorr   Ú_handle_target_dirr   )'rc   rl   rd   rA   rX   Útarget_temp_dirÚtarget_temp_dir_pathrY   rm   rn   ru   Úbuild_deleterw   rt   Ú	directoryÚreqsrv   ÚresolverÚrequirement_setÚpip_reqry   Úreqs_to_buildÚ_Úbuild_failuresÚpep517_build_failuresÚ
to_installÚshould_warn_about_conflictsrG   Ú	installedÚlib_locationsr†   ÚitemsÚresultÚitemÚinstalled_versionÚinstalled_descr²   Úshow_tracebackÚmessager/   )r1   r0   Úruní   s   











	







zInstallCommand.runc          	      sp  t |ƒ g }|T td|jd}|d }|d }|d }tj |¡rP| |¡ tj |¡rn||krn| |¡ tj |¡r„| |¡ xÜ|D ]Ô}	xÎt |	¡D ]À}
|	|krÔtj ||
¡‰ t‡ fdd„|d d… D ƒƒrÔqštj ||
¡}tj |¡rD|st	 
d	|¡ qštj |¡r t	 
d
|¡ qštj |¡r:t |¡ n
t |¡ t tj |	|
¡|¡ qšW qŠW W d Q R X d S )NÚ )r€   ÚpurelibÚplatlibÚdatac             3   s   | ]}|  ˆ ¡V  qd S )N)Ú
startswith)rz   Ús)Úddirr/   r0   r~   à  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>éÿÿÿÿzKTarget directory %s already exists. Specify --upgrade to force replacement.z„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­   Úlistdirr£   Úanyr±   ÚwarningÚislinkr’   ÚshutilÚrmtreeÚremoveÚmove)rc   r4   r´   r@   Úlib_dir_listÚschemeÚpurelib_dirÚplatlib_dirÚdata_dirÚlib_dirrÆ   Útarget_item_dirr/   )rÒ   r0   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 d|||d ¡ q\W qBW xD|D ]<}|| d }x*|| D ]\}	}
}t d||||	|
¡ qœW q‚W 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)rc   rÀ   Úpackage_setÚ	_dep_infoÚmissingÚconflictingÚproject_nameÚversionÚ
dependencyÚdep_nameÚdep_versionr+   r/   r/   r0   r¦   þ  s$    

z$InstallCommand._warn_about_conflicts)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚusagerJ   r
   rË   r³   r¦   Ú__classcell__r/   r/   )rg   r0   r3   F   s     Z8r3   c              O   s   t d| ž|Ž}|d |d gS )NrÌ   rÍ   rÎ   )rÌ   )r   )rd   ÚkwargsrÝ   r/   r/   r0   r§     s    r§   c              K   s   t dd„ ttf | ŽƒD ƒƒS )Nc             s   s   | ]}t |ƒV  qd S )N)r   )rz   Údr/   r/   r0   r~      s    z)site_packages_writable.<locals>.<genexpr>)ÚallÚsetr§   )ró   r/   r/   r0   Ú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
r–t  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:   r?   r4   r>   ri   r/   r/   r0   r   $  s0    





r   c             C   s–   dd„ }g }x8| D ]0}|j }t|ƒ}|r| d || ¡ ƒ|¡¡ qW |rnt|ƒ}|rn| d || ¡ ƒ¡¡ |svdS td d |¡¡dd	d
d dS )z’If 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)rz   r)   r/   r/   r0   r|   g  s    zKwarn_deprecated_install_options.<locals>.format_options.<locals>.<listcomp>r/   )Úoption_namesr/   r/   r0   Ú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)rX   r   r­   r¢   Úkeysr   r£   )rM   rl   rÿ   Ú	offendersÚrequirementrX   Úlocation_optionsr/   r/   r0   r™   `  s.    

r™   c             C   sš   g }|  d¡ |s,|  d¡ |  t| ƒ¡ n
|  d¡ |d  d7  < | jtjkrˆd}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_partr/   r/   r0   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$   Zpip._internal.req.req_installr%   r&   Ú	getLoggerrí   r±   r2   r3   r§   r÷   r   r™   r°   r/   r/   r/   r0   Ú<module>   s^   
   V   
72