a
    ¾†ýh!o  ã                   @   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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 e2r¢d dlm8Z8 d dl9m:Z:m;Z;m<Z< d dl=m>Z> d dlm?Z? d dl@mAZA d dl5mBZB d dlmCZC e DeE¡ZFdd„ ZGG d d!„ d!eƒZHd-d#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)Ú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)ÚBinaryAllowedPredicate)Úrunning_under_virtualenvc                    s   ‡ fdd„}|S )Nc                    s&   | j r
dS t| jƒ}ˆ  |¡}d|v S )NTZbinary)Ú
use_pep517r   ÚnameZget_allowed_formats)ÚreqZcanonical_nameZallowed_formats©Úformat_control© ú@/usr/lib/python3/dist-packages/pip/_internal/commands/install.pyÚcheck_binary_allowed6   s
    

z6get_check_binary_allowed.<locals>.check_binary_allowedr/   )r.   r1   r/   r-   r0   Úget_check_binary_allowed4   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  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j jddddd dd t | j ¡ | j jddd	d
d | j jddd	t	d | j jdddd dd | j jdddd dd | j jddd	dd | j  t 
¡ ¡ | j  t ¡ ¡ | j jdddd	dd | j jdddddgdd | j jd d!d	d"d | j jd#d$d%d	d&d | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j jd'd	d(d)d*d+ | j jd,d-d(d.d/ | j jd0d-d1d)d2d+ | j jd3d-d4d)d5d+ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ t tj| j¡}| j d6|¡ | j d6| j ¡ d S )7Nz-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_truea  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.)  On Debian systems, this is the default when running outside of a virtual environment and not as root.)r6   Úactionr9   z	--no-userÚuse_system_locationz--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--systemzDInstall using the system scheme (overrides --user on Debian systems)z-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-neededZ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store_falsez.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   )Zcmd_optsZ
add_optionr   ÚrequirementsÚconstraintsZno_depsZpreZeditableZadd_target_python_optionsr   Z	build_dirÚsrcÚignore_requires_pythonZno_build_isolationr*   Zno_use_pep517Úinstall_optionsÚglobal_optionsZ	no_binaryZonly_binaryZprefer_binaryZrequire_hashesZprogress_barZmake_option_groupZindex_groupÚparserZinsert_option_group)ÚselfZ
index_optsr/   r/   r0   Úadd_optionsU   sè    û
üüûûüü	ûüü
ûüûûþzInstallCommand.add_optionsc           )         st  |j r|jd urtdƒ‚t |¡ d}|jr2|j}tj|dd |jrP|jg}nd }|j s„|j	s„|js„|j
s„tƒ s„t ¡ dkr„d|_ |j
rd|_ tj |j¡|_|jp¨g }t dtƒ ¡ 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pHg }|  |¡}	t|ƒ}
| j ||	|
|j!d}t"|j#|j$ƒ}|  t%ƒ ¡}t|j& ddd}z\|  '||||	¡}t(||jƒ | j)||||	||j d}| j*|||||j |j|j!|j+||j,d
}|  -|¡ |j.||j d}z| /d¡}W n t0y>   d}Y n0 |j1d u }t2|d t3|j$ƒ‰ ‡ fdd„|j4 5¡ D ƒ}t6||dg g d\}}dd„ |D ƒ}|r´t7d 8d 9|¡¡ƒ‚|D ]}|j,s¸d|_:q¸| ;|¡}d }|j< oê|j=}|rü|  >|¡}|j?}|jrd}t@||||j||j	||j |jAd	}tB|j ||j|j	|jd}tC D|¡} |jEtF Gd¡d g }!|D ]P}"|"jH}#z$tI|"jH| d}$|$rš|#d |$ 7 }#W n tJy°   Y n0 |! K|#¡ qn|d urÞ| jL||  M|¡d! d" 9|!¡}%|%røtNd#|%ƒ W nP tOyJ }& z6| jPd$k}'tQ|&|'|j ƒ}(tjR|(|'d% tSW  Y d }&~&S d }&~&0 0 |jrp|s^J ‚|  T|j||j¡ tUS )&Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Zcheck_targetr   FzUsing %s)r?   r4   r>   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)ÚoptionsÚsessionÚtarget_pythonrK   Zinstall)ÚdeleterS   Zglobally_managed)Ztemp_build_dirrT   Úreq_trackerrU   Úfinderr:   )
ÚpreparerrY   rT   Úwheel_cacher:   rD   rK   rC   rA   r*   )Zcheck_supported_wheelsZpip)Úmodifying_pipc                    s   g | ]}t |ˆ ƒr|‘qS r/   )r    ©Ú.0Úr©r1   r/   r0   Ú
<listcomp>n  s
   ÿÿz&InstallCommand.run.<locals>.<listcomp>)r[   ZverifyZbuild_optionsrM   c                 S   s   g | ]}|j r|j‘qS r/   )r*   r+   r]   r/   r/   r0   ra     s   ÿzPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, i°   )ÚrootÚhomeÚprefixrF   r:   Z	pycompile)Úuserrc   rb   rd   Úisolatedr+   )Úkey)Úworking_setú-)Úresolver_variantú zSuccessfully installed %sé   )Úexc_info)Vr:   r4   r   r   Zcheck_install_build_globalr@   rA   Zcheck_dist_restrictionZpython_versionr?   r=   r)   ÚosÚgeteuidÚpathÚabspathZsrc_dirrL   ÚloggerÚdebugr   Údecide_user_installr>   rQ   rD   ÚexistsÚisdirr   Úenter_contextrM   Zget_default_sessionr   Z_build_package_finderrK   r   Z	cache_dirr.   r   Zno_cleanZget_requirementsÚ'reject_location_related_install_optionsZmake_requirement_preparerZmake_resolverrC   r*   Ztrace_basic_infoZresolveZget_requirementÚKeyErrorZsatisfied_byr   r2   rH   Úvaluesr   r   ÚformatÚjoinZlegacy_install_reasonZget_installation_orderZignore_dependenciesrG   Ú_determine_conflictsrF   r   rE   Úget_lib_location_guessesr   Z
WorkingSetÚsortÚoperatorÚ
attrgetterr+   r   Ú	ExceptionÚappendÚ_warn_about_conflictsZdetermine_resolver_variantr   ÚEnvironmentErrorÚ	verbosityÚcreate_env_error_messageÚerrorr   Ú_handle_target_dirr   ))rO   rT   ÚargsrA   Zpython_versionsrL   Útarget_temp_dirZtarget_temp_dir_pathrM   rU   rV   rY   r[   rX   Z	directoryZreqsrZ   ZresolverZrequirement_setZpip_reqr\   Zreqs_to_buildÚ_Zbuild_failuresZpep517_build_failure_namesr_   Ú
to_installZ	conflictsZshould_warn_about_conflictsrF   Z	installedZlib_locationsrh   ÚitemsÚresultÚitemZinstalled_versionZinstalled_descrˆ   Úshow_tracebackÚmessager/   r`   r0   Úrunï   sx   

ÿÿ
ûÿÿ


üýÿúö
ÿ

ÿÿ
ÿû

þþÿ

ÿ
þ
÷û
ÿ
þ
ÿ
ÿ

ÿzInstallCommand.runc                    sT  t |ƒ g }td|jd}|d }|d }|d }tj |¡rH| |¡ tj |¡rf||krf| |¡ tj |¡r|| |¡ |D ]Î}	t |	¡D ]¾}
|	|krÈtj ||
¡‰ t‡ fdd„|d d… D ƒƒrÈqŽtj ||
¡}tj |¡r6|söt	 
d	|¡ qŽtj |¡rt	 
d
|¡ qŽtj |¡r,t |¡ n
t |¡ t tj |	|
¡|¡ qŽq€d S )NÚ )rc   ÚpurelibÚplatlibÚdatac                 3   s   | ]}|  ˆ ¡V  qd S ©N)Ú
startswith)r^   Ús©Zddirr/   r0   Ú	<genexpr>ÿ  ó    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   rp   rn   ru   rƒ   Úlistdirr|   Úanyrr   ZwarningÚislinkrv   ÚshutilZrmtreeÚremoveZmove)rO   r4   r‹   r@   Zlib_dir_listÚschemeZpurelib_dirZplatlib_dirZdata_dirZlib_dirr   Ztarget_item_dirr/   r›   r0   r‰   å  sN    


ýû
þz!InstallCommand._handle_target_dirc                 C   s.   z
t |ƒW S  ty(   t d¡ Y d S 0 d S )NzwError while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new)r   r‚   rr   Z	exception)rO   r   r/   r/   r0   r}     s    
ÿz#InstallCommand._determine_conflictsc              
   C   sò   |\}\}}|s|sd S g }|dkr0|  d¡ n|dks<J ‚|  d¡ |D ]<}|| d }|| D ]"}	dj|||	d d}
|  |
¡ qbqJ|D ]P}|| d }|| D ]6\}}}d	j||||||dkrÈd
ndd}
|  |
¡ q¤qŒt d |¡¡ d S )NZlegacyz¤pip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.z2020-resolverz§pip'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.rl   )r+   ÚversionÚrequirementzg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.Úyouzyou'll)r+   r¥   r¦   Údep_nameÚdep_versionr§   Ú
)rƒ   r{   rr   Zcriticalr|   )rO   Zconflict_detailsrj   Zpackage_setZmissingZconflictingÚpartsZproject_namer¥   Z
dependencyr’   r¨   r©   r,   r/   r/   r0   r„   (  sH    ÿÿÿúÿ÷z$InstallCommand._warn_about_conflictsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZusagerP   r
   r“   r‰   r}   r„   r/   r/   r/   r0   r3   A   s    
 v8r3   Fc                 C   s$   t d| ||||d}|d |d gS )Nr”   )re   rc   rb   rf   rd   r•   r–   r   )re   rc   rb   rf   rd   r¤   r/   r/   r0   r~   ^  s    
ÿr~   c                 C   s   t dd„ tt| |dƒD ƒƒS )Nc                 s   s   | ]}t |ƒV  qd S r˜   r   )r^   Údr/   r/   r0   rœ   m  s   z)site_packages_writable.<locals>.<genexpr>©rb   rf   )ÚallÚsetr~   r±   r/   r/   r0   Úsite_packages_writablek  s
    
ÿÿr´   c                 C   s¤   | dur| st  d¡ dS | rF|r*tdƒ‚tƒ r8tdƒ‚t  d¡ dS | du sRJ ‚|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 disabledr±   z0Non-user install because site-packages writeablezMDefaulting to user installation because normal site-packages is not writeable)	rr   rs   r   r   r   ÚsiteÚENABLE_USER_SITEr´   Úinfo)r:   r?   r4   r>   rQ   r/   r/   r0   rt   s  s4    
ÿÿ




rt   c                 C   sŠ   dd„ }g }| D ]0}|j }t|ƒ}|r| d || ¡ ƒ|¡¡ q|rjt|ƒ}|rj| d || ¡ ƒ¡¡ |srdS t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Œ   ri   )r{   Úreplace)r^   r+   r/   r/   r0   ra   ¶  r   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 lineNz˜Location-changing options found in --install-option: {}. This is unsupported, use pip-level options like --user, --prefix, --root, and --target instead.z; )rL   r   rƒ   r{   Úkeysr   r|   )rH   rT   r¹   Z	offendersr¦   rL   Zlocation_optionsr/   r/   r0   rx   ¯  s4    ÿÿ
ÿÿýÿrx   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ž   rª   z"Consider using the `--user` optionzCheck the permissionsz or z.
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‡   )FNNFN)NNNF)NZ
__future__r   r½   Zloggingr€   rn   r¢   rµ   Zoptparser   Zpip._vendorr   Z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!   Útypingr"   r#   r$   Z#pip._internal.models.format_controlr%   r&   Zpip._internal.req.req_installr'   r(   r)   Z	getLoggerr¬   rr   r2   r3   r~   r´   rt   rx   r‡   r/   r/   r/   r0   Ú<module>   sn   
    "     û

    û
<*