o
    ¾Ôiw  ã                   @  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	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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#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l0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZG e9eHƒZIG dd„ deƒZJ					d;d<d(d)„ZKd=d*d+„ZL				d>d?d2d3„ZMd@d9d:„ZNdS )Aé    )ÚannotationsN)ÚSUPPRESS_HELPÚValues)ÚPath)Úcanonicalize_name)ÚInvalidProxyURL)Ú
print_json)Ú
WheelCache)Ú
cmdoptions)Úmake_target_python)ÚRequirementCommandÚwith_cleanup)ÚERRORÚSUCCESS)ÚCommandErrorÚInstallationErrorÚInstallWheelBuildError)Ú
get_scheme)Úget_environment)ÚInstallationReport)Úget_build_tracker)ÚConflictDetailsÚcheck_install_conflicts)Úinstall_given_reqs)ÚInstallRequirement)ÚWINDOWS©Útest_writable_dir)Ú	getLogger)Úcheck_externally_managedÚ
ensure_dirÚget_pip_versionÚ(protect_pip_from_modification_on_windowsÚwarn_if_run_as_rootÚwrite_output)ÚTempDirectory)Úrunning_under_virtualenvÚvirtualenv_no_global)Úbuildc                   @  sJ   e Zd ZdZdZd!dd„Zed"dd„ƒZd#dd„Zd$dd„Z	d%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> ...ÚreturnÚNonec                 C  s¶  | 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 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 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/d0 | j jd1dd2d,d3d | j jd4dd5d,d6d | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ | j  t ¡ ¡ t tj| j¡}| j d7|¡ | j d7| j ¡ | j jd8d9d:d d;d d S )<Nz	--dry-runÚ
store_trueÚdry_runFzŒDon't actually install anything, just print what would be. Can be used in combination with --ignore-installed to 'resolve' the requirements.)ÚactionÚdestÚdefaultÚhelpz-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.)r/   Úmetavarr0   r1   z--userÚuse_user_sitez¸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/   r.   r1   z	--no-userÚstore_falsez--rootÚ	root_pathz=Install everything relative to this alternate root directory.z--prefixÚprefix_patha[  Installation prefix where lib, bin and other top-level folders are placed. Note that the resulting installation may contain scripts and other resources which reference the Python interpreter of pip, and not that of ``--prefix``. See also the ``--python`` option if the intention is to install packages into another (possibly pip-free) environment.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).)r/   r0   Úchoicesr1   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 bytecodez--no-compilez.Do not compile Python source files to bytecode)r.   r/   r1   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--reportÚjson_report_fileÚfileaW  Generate a JSON file describing what pip did to install the provided requirements. Can be used in combination with --dry-run and --ignore-installed to 'resolve' the requirements. When - is used as file name it writes to stdout. When writing to stdout, please combine with the --quiet option to avoid mixing pip logging output with JSON output.)Zcmd_optsZ
add_optionr
   ÚrequirementsZconstraintsZbuild_constraintsZno_depsZpreZeditableZadd_target_python_optionsr   ÚsrcÚignore_requires_pythonZno_build_isolationZ
use_pep517Zcheck_build_depsÚoverride_externally_managedZconfig_settingsZ	no_binaryZonly_binaryZprefer_binaryZrequire_hashesÚprogress_barÚroot_user_actionZmake_option_groupZindex_groupÚparserZinsert_option_group)ÚselfZ
index_opts© rK   ú>lib/python3.10/site-packages/pip/_internal/commands/install.pyÚadd_optionsV   s   úùûüûúúúüúûüûûþ
úzInstallCommand.add_optionsÚoptionsr   Úargsú	list[str]Úintc           ,      C  sÞ  |j r|jd urtdƒ‚|jo|j o!|jd u o!|jd u o!|jd u }|r*|js*tƒ  d}|j	r2|j
}t |¡ tj|dd t dtƒ ¡ t|j |j|j|j|jd|_ d }d }|jr…d|_tj |j¡|_tj |j¡rxtj |j¡sxtdƒ‚tdd	}|j}|  |¡ |  |¡}t|ƒ}| j||||jd
}	|  tƒ ¡}
t|j  ddd}z|  !|||	|¡}t"|j#ƒ}|D ]}d|_$q¸| j%|||
||	|j | j&d}| j'||	|||j |j|j|j(||j)d
}|  *|	¡ |j+||j d}|jr)t,|j-ƒ}|jdkrt.| /¡ d n$t0|jddd}t1j2| /¡ |ddd W d   ƒ n	1 s$w   Y  |jrJt3dd„ |j-D ƒƒ}|rGt4dd 5dd„ |D ƒ¡ƒ t6W S | 7|j8 9¡ ¡ z| :d¡}W n t;ye   d}Y nw |j<d u }t=|d dd „ |j-D ƒ}t>||dd!\}}|rˆt?|ƒ‚| @|¡}d }|jA o–|jB}|rŸ|  C|¡}|jD}|jsª|jr¬d}tE||j||j||j |jF|jGd"}tH|j ||j|j|jd#}tI|ƒ} |jJtK Ld$¡d% g }!i }"|  M¡ D ]	}#|#jN|"|#jO< qß|D ] }$|$jP}%|" QtR|%ƒd ¡}&|&r|%› d|&› }'n|%}'|! S|'¡ që|d ur| jT||  U|¡d& d 5|!¡}(|(r(t4d'|(ƒ W n( tVyQ }) z| j&d(k}*tW|)|*|j ƒ}+tjX|+|*d) tYW  Y d })~)S d })~)ww |jrd|s[J ‚|  Z|j||j	¡ |j[d*krmt\ƒ  t6S )+Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Zcheck_targetzUsing %s)r8   r2   r7   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)rN   ÚsessionÚtarget_pythonrE   Úinstall)ÚdeleterT   Zglobally_managed)Ztemp_build_dirrN   Úbuild_trackerrU   Úfinderr5   Ú	verbosity)
ÚpreparerrZ   rN   Úwheel_cacher5   r=   rE   r<   r:   Zpy_version_info)Zcheck_supported_wheelsú-)ÚdataÚwzutf-8)Úencodingé   F)ÚindentZensure_asciic                 s  s$    | ]}|j d  |j d fV  qdS )ÚnameÚversionN)Zmetadata©Ú.0ÚrrK   rK   rL   Ú	<genexpr>‘  s
   € ÿ
ÿz%InstallCommand.run.<locals>.<genexpr>zWould install %sú c                 s  s    | ]}d   |¡V  qdS )r^   N)Újoin)rg   ÚitemrK   rK   rL   ri   ˜  ó   € Úpip)Úmodifying_pipc                 S  s   g | ]}|j s|‘qS rK   )Zis_wheelrf   rK   rK   rL   Ú
<listcomp>­  s
    ÿÿz&InstallCommand.run.<locals>.<listcomp>)r]   Zverify)ÚrootÚhomeÚprefixr?   r5   Z	pycompilerG   )Úuserrr   rq   rs   Úisolatedrd   )Úkey)Úresolver_variantzSuccessfully installed %sé   )Úexc_infoÚwarn)]r5   r2   r   r-   rA   r7   r8   rF   r   r9   r:   r
   Zcheck_build_constraintsZcheck_dist_restrictionÚloggerÚverboser!   Údecide_user_installrR   r=   ÚosÚpathÚabspathÚexistsÚisdirr%   Úenter_contextZget_default_sessionr   Z_build_package_finderrE   r   Zno_cleanZget_requirementsr	   Z	cache_dirZpermit_editable_wheelsZmake_requirement_preparerr[   Zmake_resolverr<   Zpython_versionZtrace_basic_infoÚresolver   Zrequirements_to_installr   Zto_dictÚopenÚjsonÚdumpÚsortedr$   rk   r   Z prepare_linked_requirements_morerC   ÚvaluesZget_requirementÚKeyErrorZsatisfied_byr"   r(   r   Zget_installation_orderZignore_dependenciesr@   Ú_determine_conflictsr?   r   r>   rG   Úget_lib_location_guessesr   ÚsortÚoperatorÚ
attrgetterZiter_all_distributionsre   Zcanonical_namerd   Úgetr   ÚappendÚ_warn_about_conflictsZdetermine_resolver_variantÚOSErrorÚcreate_os_error_messageÚerrorr   Ú_handle_target_dirrH   r#   ),rJ   rN   rO   Z#installing_into_current_environmentr:   Útarget_temp_dirZtarget_temp_dir_pathrU   rV   rZ   rY   Z	directoryZreqsr]   Úreqr\   ZresolverZrequirement_setÚreportÚfZwould_install_itemsZpip_reqro   Zreqs_to_buildÚ_Zbuild_failuresÚ
to_installÚ	conflictsZshould_warn_about_conflictsr?   Z	installedZlib_locationsÚenvZsummaryZinstalled_versionsZdistributionÚpackageZdisplay_namere   ÚtextZinstalled_descr•   Úshow_tracebackÚmessagerK   rK   rL   Úrun  s‚  ÿþüÿþ
ûþýÿ


üý
ù	ö
ÿ
ÿþþÿÿ

ÿ
ý
ÿ
øû
þ
þ€
ý€ö

ÿzInstallCommand.runr2   Ústrr—   r%   r9   Úboolc                   sH  t |ƒ g }td|jd}|j}|j}|j}tj |¡r!| |¡ tj |¡r0||kr0| |¡ tj |¡r;| |¡ |D ]d}	t 	|	¡D ]\}
|	|kratj 
||
¡‰ t‡ fdd„|d d… D ƒƒraqDtj 
||
¡}tj |¡r•|swt d|¡ qDtj |¡r„t d|¡ qDtj |¡rt |¡ nt |¡ t tj 
|	|
¡|¡ qDq=d S )NÚ )rr   c                 3  s    | ]}|  ˆ ¡V  qd S ©N)Ú
startswith)rg   Ús©ÚddirrK   rL   ri   *  rm   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   ÚpurelibÚplatlibr_   r~   r   r‘   Úlistdirrk   Úanyr{   ZwarningÚislinkr‚   ÚshutilÚrmtreeÚremoveÚmove)rJ   r2   r—   r9   Zlib_dir_listÚschemeZpurelib_dirZplatlib_dirZdata_dirZlib_dirrl   Ztarget_item_dirrK   rª   rL   r–     sL   


ýû
äÿz!InstallCommand._handle_target_dirrœ   úlist[InstallRequirement]úConflictDetails | Nonec                 C  s*   zt |ƒW S  ty   t d¡ Y d S w )NzwError while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new)r   Ú	Exceptionr{   Ú	exception)rJ   rœ   rK   rK   rL   r‹   E  s   
ÿûz#InstallCommand._determine_conflictsÚconflict_detailsr   rw   c              
   C  sø   |\}\}}|s|sd S g }|dkr|  d¡ n|dksJ ‚|  d¡ |D ]!}|| d }|| D ]}	|› d|› d|	d › d	}
|  |
¡ q1q%|D ](}|| d }|| D ]\}}}d
j||||||dkrgdndd}
|  |
¡ qUqIt d |¡¡ d S )NÚ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
resolvelibz§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   rj   z
 requires rx   z, which is not installed.zg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.Úyouzyou'll)rd   re   ZrequirementÚdep_nameÚdep_versionr½   Ú
)r‘   Úformatr{   Zcriticalrk   )rJ   r»   rw   Zpackage_setÚmissingZconflictingÚpartsZproject_namere   Z
dependencyr¢   r¾   r¿   r˜   rK   rK   rL   r’   Q  sD   ÿÿÿû÷ôz$InstallCommand._warn_about_conflictsN)r*   r+   )rN   r   rO   rP   r*   rQ   )r2   r¤   r—   r%   r9   r¥   r*   r+   )rœ   r·   r*   r¸   )r»   r   rw   r¤   r*   r+   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚusagerM   r   r£   r–   r‹   r’   rK   rK   rK   rL   r)   B   s    
 A 
y
6r)   Frt   r¥   rr   ú
str | Nonerq   ru   rs   r*   rP   c                 C  s    t d| ||||d}|j|jgS )Nr¦   )rt   rr   rq   ru   rs   )r   r­   r®   )rt   rr   rq   ru   rs   r¶   rK   rK   rL   rŒ   „  s   úrŒ   c                 C  s   t dd„ tt| |dƒD ƒƒS )Nc                 s  s    | ]}t |ƒV  qd S r§   r   )rg   ÚdrK   rK   rL   ri   —  s
   € ÿ
ÿz)site_packages_writable.<locals>.<genexpr>©rq   ru   )ÚallÚsetrŒ   rË   rK   rK   rL   Úsite_packages_writable–  s   þrÎ   r5   úbool | Noner8   r2   r7   rR   c                 C  s²   | dur| st  d¡ dS | r*|rtdƒ‚tƒ rtdƒ‚tjs#tdƒ‚t  d¡ dS | du s0J ‚|s4|r;t  d	¡ dS tjsEt  d
¡ dS t||drRt  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.zTCan not perform a '--user' install. User site-packages are disabled for this Python.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{   Údebugr   r'   r   ÚsiteÚENABLE_USER_SITErÎ   Úinfo)r5   r8   r2   r7   rR   rK   rK   rL   r}     s@   
ÿÿÿ



ÿr}   r•   r“   r¡   Úusing_user_siter¤   c                 C  s  g }|  d¡ |s|  d¡ |  t| ƒ¡ n|  d¡ |d  d7  < | jtjkrGd}d}tƒ s=|s=| |d| ¡ g¡ n|  |¡ |  d	¡ t| ƒtu rW|  d
¡ |  d	¡ t	rƒ| jtj
tjfv rƒ| jrƒtdd„ t| jƒjD ƒƒrw|  d¡ t| jƒdkrƒ|  d¡ d |¡ ¡ d S )zrFormat an error message for an OSError

    It may occur anytime during the execution of the install command.
    z,Could not install packages due to an OSErrorz: Ú.r¬   rÀ   z"Consider using the `--user` optionzCheck the permissionsz or z.
zHConsider checking your local proxy configuration with "pip config debug"c                 s  s    | ]	}t |ƒd kV  qdS )éÿ   N)Úlen)rg   ÚpartrK   rK   rL   ri     s   € z*create_os_error_message.<locals>.<genexpr>z“HINT: This error might be caused by a file or folder name exceeding 255 characters, which is a Windows limitation even if long paths are enabled.
 i  zÉHINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
r¦   )r‘   r¤   ÚerrnoZEACCESr&   ÚextendÚlowerÚtyper   r   ÚEINVALÚENOENTÚfilenamer°   r   rÃ   r×   rk   Ústrip)r•   r¡   rÔ   rÃ   Zuser_option_partZpermissions_partrK   rK   rL   r”   â  sD   



ýÿ

ÿ
ÿÿr”   )FNNFN)rt   r¥   rr   rÉ   rq   rÉ   ru   r¥   rs   rÉ   r*   rP   )rq   rÉ   ru   r¥   r*   r¥   )NNNF)r5   rÏ   r8   rÉ   r2   rÉ   r7   rÉ   rR   r¥   r*   r¥   )r•   r“   r¡   r¥   rÔ   r¥   r*   r¤   )OZ
__future__r   rÙ   r†   rŽ   r~   r²   rÑ   Zoptparser   r   Úpathlibr   Zpip._vendor.packaging.utilsr   Zpip._vendor.requests.exceptionsr   Zpip._vendor.richr   Z!pip._internal.self_outdated_checkrn   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   r   Zpip._internal.locationsr   Zpip._internal.metadatar   Z(pip._internal.models.installation_reportr   Z,pip._internal.operations.build.build_trackerr   Zpip._internal.operations.checkr   r   Zpip._internal.reqr   Zpip._internal.req.req_installr   Zpip._internal.utils.compatr   Zpip._internal.utils.filesystemr   Zpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r    r!   r"   r#   r$   Zpip._internal.utils.temp_dirr%   Zpip._internal.utils.virtualenvr&   r'   Zpip._internal.wheel_builderr(   rÄ   r{   r)   rŒ   rÎ   r}   r”   rK   rK   rK   rL   Ú<module>   sh         Gû
	ûE