a
    û"©b[m  ã                   @   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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 e4�r®d dlm:Z: d dl;m<Z<m=Z=m>Z> d dl?m@Z@ d dlmAZA d dlBmCZC d dl7mDZD e EeF¡ZGdd„ ZHG d d!„ d!eƒZId-d#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Úwith_cleanup)ÚERRORÚSUCCESS)ÚCommandErrorÚInstallationError©Údistutils_scheme)Úcheck_install_conflicts)Úinstall_given_reqs)Úget_requirement_tracker)Útoday_is_later_than)Ú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                    s&   | j r
dS t| jƒ}ˆ  |¡}d|v S )NTÚbinary)Ú
use_pep517r   ÚnameÚget_allowed_formats)ÚreqÚcanonical_nameÚallowed_formats©Úformat_control© úg/home/yuhw/wc/wire-cell-python-pr-11/pr11/lib/python3.9/site-packages/pip/_internal/commands/install.pyÚcheck_binary_allowed6   s
    

z6get_check_binary_allowed.<locals>.check_binary_allowedr3   )r2   r5   r3   r1   r4   Úget_check_binary_allowed4   s    r6   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   sz  | 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  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d-dd.d'd/d)� | j jd0dd1d'd2d)� | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ t tj| j¡}| j d3|¡ | j d3| j ¡ 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.))r:   Ú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Ú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).)r:   r<   Úchoicesr=   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@   r:   r<   r=   z--no-compilez.Do not compile Python source files to bytecode)r@   r:   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   )Ú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Ú
index_optsr3   r3   r4   Úadd_optionsU   sÜ    û
üüûûü	ûüü
ûüûûþzInstallCommand.add_optionsc           )         s  |j r|jd urtdƒ‚t |¡ d}|jr2|j}tj|dd� |jpHg }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pàg }|  |¡}t|ƒ}	| j|||	|jd
�}
|j�p|j }t|j |j!ƒ}|  t"ƒ ¡}t|j|ddd�}�zZ|  #|||
|¡}t$||jƒ | j%|||||
|j d�}| j&||
|||j |j|j|j'||j(d�
}|  )|
¡ |j*||j d�}z| +d¡}W n t,�yæ   d}Y n0 |j-d u }t.|d� t/|
j!ƒ‰ ‡ fdd„|j0 1¡ D ƒ}t2||g g d�\}}dd„ |D ƒ}|�rZt3d 4d 5|¡¡ƒ‚|D ]}|j(�s^d|_6�q^| 7|¡}d }|j8 �o�|j9}|�r¢|  :|¡}|j;}|j�r´d}t<||||j||j||j |j=d�	}t>|j ||j|j|jd�}t? @|¡} |jAtB Cd¡d� g }!|D ]P}"|"jD}#z$tE|"jD| d�}$|$�r@|#d|$ 7 }#W n tF�yV   Y n0 |! G|#¡ �q|d u�r„| jH|d |jIv d!� d" 5|!¡}%|%�ržtJd#|%ƒ W nP tK�yð }& z6| jLd$k}'tM|&|'|j ƒ}(t	jN|(|'d%� tOW  Y d }&~&S d }&~&0 0 |j�r|�sJ ‚|  P|j||j¡ tQS )&Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Úcheck_targetzUsing %s)rC   r8   rB   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)ÚoptionsÚsessionÚtarget_pythonrW   Úinstall)Údeleterk   Úglobally_managed)Útemp_build_dirrl   Úreq_trackerrm   Úfinderr>   )
Úpreparerrt   rl   Úwheel_cacher>   rI   rW   rH   rE   r+   )Úcheck_supported_wheelsÚpipF)Úmodifying_pipc                    s   g | ]}t |ˆ ƒr|‘qS r3   )r!   ©Ú.0Úr©r5   r3   r4   Ú
<listcomp>W  s
   ÿÿz&InstallCommand.run.<locals>.<listcomp>)rv   Úbuild_optionsr[   c                 S   s   g | ]}|j r|j‘qS r3   )r+   r,   rz   r3   r3   r4   r~   g  s   ÿzPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, i°   )ÚrootÚhomeÚprefixrK   r>   Ú	pycompile)Úuserr�   r€   r‚   Úisolatedr,   )Úkey)Úworking_setú-z2020-resolver)Únew_resolverú zSuccessfully installed %sé   )Úexc_info)Rr>   r8   r   r   Úcheck_install_build_globalrD   rE   Úcheck_dist_restrictionrZ   ÚloggerÚdebugr   Údecide_user_installrC   rB   ri   rI   ÚosÚpathÚabspathÚexistsÚisdirr   Úenter_contextr[   Úget_default_sessionr   Ú_build_package_finderrW   Úno_cleanrU   r   Ú	cache_dirr2   r   Úget_requirementsÚ'reject_location_related_install_optionsÚmake_requirement_preparerÚmake_resolverrH   r+   Útrace_basic_infoÚresolveÚget_requirementÚKeyErrorÚsatisfied_byr   r6   rO   Úvaluesr    r   ÚformatÚjoinÚlegacy_install_reasonÚget_installation_orderÚignore_dependenciesrL   Ú_determine_conflictsrK   r   rJ   Úget_lib_location_guessesr   Ú
WorkingSetÚsortÚoperatorÚ
attrgetterr,   r   Ú	ExceptionÚappendÚ_warn_about_conflictsÚfeatures_enabledr   ÚEnvironmentErrorÚ	verbosityÚcreate_env_error_messageÚerrorr   Ú_handle_target_dirr   ))re   rl   ÚargsrE   rZ   Útarget_temp_dirÚtarget_temp_dir_pathr[   rm   rn   rt   Úbuild_deleterv   rs   Ú	directoryÚreqsru   ÚresolverÚrequirement_setÚpip_reqry   Úreqs_to_buildÚ_Úbuild_failuresÚpep517_build_failure_namesr|   Ú
to_installÚ	conflictsÚshould_warn_about_conflictsrK   Ú	installedÚlib_locationsr‡   ÚitemsÚresultÚitemÚinstalled_versionÚinstalled_descr¸   Úshow_tracebackÚmessager3   r}   r4   Úrunå   s`   

ûÿÿ



üüÿúö
ÿ

ÿÿ
ÿü
	þþÿ

ÿ
þ
÷û
ÿ
þ
ÿ
ÿ

ÿ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Ú )r�   ÚpurelibÚplatlibÚdatac                 3   s   | ]}|  ˆ ¡V  qd S ©N)Ú
startswith)r{   Ús©Úddirr3   r4   Ú	<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   r“   r’   r•   r²   Úlistdirr§   Úanyr�   ÚwarningÚislinkr–   ÚshutilÚrmtreeÚremoveÚmove)re   r8   r»   rD   Úlib_dir_listÚschemeÚpurelib_dirÚplatlib_dirÚdata_dirÚlib_dirrÎ   Útarget_item_dirr3   rÛ   r4   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±   r�   Ú	exception)re   rÇ   r3   r3   r4   r«     s    
ÿz#InstallCommand._determine_conflictsc              	   C   s   |\}\}}|s|sd S g }|s6|  d¡ |  d¡ n,tdddd�sb|  d¡ d}|  d	 |¡¡ |D ]<}|| d
 }	|| D ]"}
dj||	|
d d�}|  |¡ q~qf|D ]B}|| d
 }	|| D ](\}}}dj||	|||d�}|  |¡ qÀq¨t d |¡¡ d S )Nz¢After 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.
iä  é   é   )ÚyearÚmonthÚdayz¸Pip 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‹   )r,   ÚversionÚrequirementzh{name} {version} requires {requirement}, but you'll have {dep_name} {dep_version} which is incompatible.)r,   rõ   rö   Údep_nameÚdep_versionÚ
)r²   r   r¦   r�   Úcriticalr§   )re   Úconflict_detailsr‰   Úpackage_setÚmissingÚconflictingÚpartsÚ	form_linkÚproject_namerõ   Ú
dependencyrÒ   r÷   rø   r.   r3   r3   r4   r³     sX    ÿÿÿÿÿÿúÿø
z$InstallCommand._warn_about_conflictsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úusagerg   r
   rÓ   r¹   r«   r³   r3   r3   r3   r4   r7   A   s    
 h8r7   Fc                 C   s$   t d| ||||d�}|d |d gS )NrÔ   )r„   r�   r€   r…   r‚   rÕ   rÖ   r   )r„   r�   r€   r…   r‚   ré   r3   r3   r4   r¬   P  s    
ÿr¬   c                 C   s   t dd„ tt| |d�ƒD ƒƒS )Nc                 s   s   | ]}t |ƒV  qd S rØ   r   )r{   Údr3   r3   r4   rÝ   _  s   z)site_packages_writable.<locals>.<genexpr>©r€   r…   )ÚallÚsetr¬   r	  r3   r3   r4   Úsite_packages_writable]  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)	r�   r�   r   r   r   ÚsiteÚENABLE_USER_SITEr  Úinfo)r>   rC   r8   rB   ri   r3   r3   r4   r‘   e  s4    
ÿÿ




r‘   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Ä   rˆ   )r¦   Úreplace)r{   r,   r3   r3   r4   r~   ¨  rÞ   zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r3   )Úoption_namesr3   r3   r4   Ú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; )rZ   r   r²   r¦   Úkeysr   r§   )rO   rl   r  Ú	offendersrö   rZ   Úlocation_optionsr3   r3   r4   r�   ¡  s4    ÿÿ
ÿÿýÿ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ß   rù   z"Consider using the `--user` optionzCheck the permissionsz or z.
rÔ   )r²   ÚstrÚerrnoÚEACCESÚextendÚlowerr§   Ústrip)r¸   rÑ   Úusing_user_siterÿ   Úuser_option_partÚpermissions_partr3   r3   r4   r·   Ë  s$    


þ

r·   )FNNFN)NNNF)OÚ
__future__r   r  Úloggingr¯   r’   rä   r  Úoptparser   Úpip._vendorr   Z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.datetimer   Ú"pip._internal.utils.distutils_argsr   Úpip._internal.utils.filesystemr   Úpip._internal.utils.miscr   r   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%   Ú#pip._internal.models.format_controlr&   r'   Zpip._internal.req.req_installr(   r)   Ú	getLoggerr  r�   r6   r7   r¬   r  r‘   r�   r·   r3   r3   r3   r4   Ú<module>   sn   
         û

    û
<*