a
    0fr                     @   s"  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
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(m)Z) d dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZBmCZC e4eDZEG dd deZFd)eGeeH eeH eGeeH e
eH dddZIeeH eGeGd d!d"ZJd*eeG eeH eeH eeH eGeGd#d$d%ZKeLeGeGeHd&d'd(ZMdS )+    N)SUPPRESS_HELPValues)ListOptional)canonicalize_name)
print_json)
WheelCache)
cmdoptions)make_target_python)RequirementCommandwith_cleanup)ERRORSUCCESS)CommandErrorInstallationError)
get_scheme)get_environment)InstallationReport)get_build_tracker)ConflictDetailscheck_install_conflicts)install_given_reqs)InstallRequirementcheck_legacy_setup_py_options)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)build should_build_for_install_commandc                   @   sz   e Zd ZdZdZddddZeeee	 e
ddd	Ze	eedd
ddZee ee dddZee	d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> ...N)returnc                 C   s  | 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 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_runFzDon'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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.)r.   metavarr/   r0   z--useruse_user_sitezInstall 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-   r0   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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).)r.   r/   choicesr0   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 bytecodez--no-compilez.Do not compile Python source files to bytecode)r-   r.   r0   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.)cmd_opts
add_optionr	   requirementsconstraintsno_depspreeditableadd_target_python_optionsr   srcignore_requires_pythonno_build_isolation
use_pep517no_use_pep517check_build_depsoverride_externally_managedconfig_settingsglobal_options	no_binaryonly_binaryprefer_binaryrequire_hashesprogress_barroot_user_actionmake_option_groupindex_groupparserinsert_option_group)self
index_opts r`   W/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/commands/install.pyadd_optionsI   s   zInstallCommand.add_options)optionsargsr*   c           .      C   s  |j r|jd urtd|jo"|j oB|jd u oB|jd u oB|jd u }|rT|jsTt  d}|j	rd|j
}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rtj|jstdtdd	}|j}| | |jpg }| |}t|}	| j|||	|jd
}
| t }t|j  ddd}z,| !|||
|}t"|| t#|j$}|D ]}d|_%q~| j&|||||
|j | j'd}| j(||
|||j |j|j|j)||j*|j+d}| ,|
 |j-||j d}|jrft.|j/}|jdkrt0|1 d nHt2|jddd&}t3j4|1 |ddd W d    n1 s\0    Y  |jrt5dd |j/D }|rt6dd7dd |D  t8W S z|9d}W n t:y   d}Y n0 |j;d u }|rdd l<}t=|d d d! |j>? D }t@||dg |d"\}}|r@tAd#Bd$7d%d |D |C|}d }|jD o\|jE}|rn| F|}|jG}|js|jrd}tH|||j||j||j |jId&} tJ|j ||j|j|jd'}!tK|!}"| jLtMNd(d) g }#i }$|"O D ]}%|%jP|$|%jQ< q| D ]@}&|&jR}'|$StT|'d }(|(r4|' d|( })n|'})|#U|) q|d urd| jV|| W|d* d7|#}*|*r~t6d+|* W nP tXy }+ z6| j'd,k},tY|+|,|j }-tjZ|-|,d- t[W  Y d }+~+S d }+~+0 0 |jr|sJ | \|j||j	 |j]d.krt^  t8S )/Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)check_targetzUsing %s)r7   r1   r6   isolated_modez=Target path exists but is not a directory, will not continue.target)kind)rc   sessiontarget_pythonrL   install)deleterh   globally_managed)temp_build_dirrc   build_trackerri   finderr4   	verbosity)preparerrp   rc   wheel_cacher4   r=   rL   r<   r9   rN   py_version_info)check_supported_wheels-)datawzutf-8)encoding   F)indentensure_asciic                 s   s"   | ]}|j d  |j d fV  qdS )nameversionN)metadata.0rr`   r`   ra   	<genexpr>  s   z%InstallCommand.run.<locals>.<genexpr>zWould install %s c                 s   s   | ]}d  |V  qdS )rv   N)join)r   itemr`   r`   ra   r         pipr   )modifying_pipc                 S   s   g | ]}t |r|qS r`   )r(   r   r`   r`   ra   
<listcomp>  s   z&InstallCommand.run.<locals>.<listcomp>)rs   verifybuild_optionsrS   zUERROR: Failed to build installable wheels for some pyproject.toml based projects ({})z, c                 s   s   | ]}|j V  qd S N)r}   r   r`   r`   ra   r     r   )roothomeprefixr?   r4   	pycompile)userr   r   r   isolatedr}   )key)resolver_variantzSuccessfully installed %s   )exc_infowarn)_r4   r1   r   r,   rA   r6   r7   rQ   r   r8   r9   r	   check_dist_restrictionloggerverboser    decide_user_installrf   r=   ospathabspathexistsisdirr$   enter_contextrS   get_default_sessionr
   _build_package_finderrL   r   no_cleanget_requirementsr   r   	cache_dirpermit_editable_wheelsmake_requirement_preparerrq   make_resolverr<   rN   python_versiontrace_basic_inforesolver   requirements_to_installr   to_dictopenjsondumpsortedr#   r   r   get_requirementKeyErrorsatisfied_by!pip._internal.self_outdated_checkr!   rE   valuesr'   r   formatget_installation_orderignore_dependenciesr@   _determine_conflictsr?   r   r>   get_lib_location_guessesr   sortoperator
attrgetteriter_all_distributionsr~   canonical_namer}   getr   append_warn_about_conflictsdetermine_resolver_variantOSErrorcreate_os_error_messageerrorr   _handle_target_dirrY   r"   ).r^   rc   rd   #installing_into_current_environmentr9   target_temp_dirtarget_temp_dir_pathrS   ri   rj   rp   ro   	directoryreqsrs   reqrr   resolverrequirement_setreportfwould_install_itemspip_reqr   r   reqs_to_build_build_failures
to_install	conflictsshould_warn_about_conflictsr?   	installedlib_locationsenvsummaryZinstalled_versionsdistributionpackageZdisplay_namer~   textinstalled_descr   show_tracebackmessager`   r`   ra   run
  s   





	

6










zInstallCommand.run)r1   r   r8   r*   c                    sN  t | g }td|jd}|j}|j}|j}tj|rB|| tj|r`||kr`|| tj|rv|| |D ]}	t	|	D ]}
|	|krtj
||
 t fdd|d d D rqtj
||
}tj|r0|std| qtj|rtd| qtj|r&t| n
t| ttj
|	|
| qqzd S )N )r   c                 3   s   | ]}|  V  qd S r   )
startswith)r   sddirr`   ra   r   )  r   z4InstallCommand._handle_target_dir.<locals>.<genexpr>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   purelibplatlibrw   r   r   r   listdirr   anyr   warningislinkr   shutilrmtreeremovemove)r^   r1   r   r8   lib_dir_listschemepurelib_dirplatlib_dirdata_dirlib_dirr   target_item_dirr`   r   ra   r     sH    



z!InstallCommand._handle_target_dir)r   r*   c                 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   	Exceptionr   	exception)r^   r   r`   r`   ra   r   D  s    
z#InstallCommand._determine_conflicts)conflict_detailsr   r*   c              
   C   s   |\}\}}|s|sd S g }|dkr0| d n|dks<J | d |D ]B}|| d }|| D ](}	| d| d|	d  d	}
| |
 qbqJ|D ]P}|| d }|| D ]6\}}}d
j||||||dkrdndd}
| |
 qqtd| d S )Nlegacyzpip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.
resolvelibzpip'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   r   z
 requires r   z, which is not installed.zg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.youzyou'll)r}   r~   requirementdep_namedep_versionr  
)r   r   r   criticalr   )r^   r  r   package_setmissingconflictingpartsproject_namer~   
dependencyr   r  r  r   r`   r`   ra   r   P  s@    z$InstallCommand._warn_about_conflicts)__name__
__module____qualname____doc__usagerb   r   r   r   strintr   r$   boolr   r   r   r   r   r   r`   r`   r`   ra   r)   5   s"    B  7r)   F)r   r   r   r   r   r*   c                 C   s    t d| ||||d}|j|jgS )Nr   )r   r   r   r   r   )r   r   r   )r   r   r   r   r   r   r`   r`   ra   r     s    r   )r   r   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`   ra   r     s   z)site_packages_writable.<locals>.<genexpr>r   r   )allsetr   r  r`   r`   ra   site_packages_writable  s    r  )r4   r7   r1   r6   rf   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
rt 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   debugr   r&   r   siteENABLE_USER_SITEr  info)r4   r7   r1   r6   rf   r`   r`   ra   r     s8    




r   )r   r   using_user_siter*   c                 C   s   g }| d |s,| d | t|  n
| d |d  d7  < | jtjkrd}d}t sz|sz||d| g n
| | | d	 tr| jtjkr| j	rt
| 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.
i  zHINT: 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  errnoEACCESr%   extendlowerr   ENOENTfilenamelenr   strip)r   r   r!  r  user_option_partpermissions_partr`   r`   ra   r     s>    






r   )FNNFN)NNNF)Nr#  r   r   r   r   r  optparser   r   typingr   r   Zpip._vendor.packaging.utilsr   pip._vendor.richr   pip._internal.cacher   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.metadatar   (pip._internal.models.installation_reportr   ,pip._internal.operations.build.build_trackerr   pip._internal.operations.checkr   r   pip._internal.reqr   Zpip._internal.req.req_installr   r   pip._internal.utils.compatr   pip._internal.utils.filesystemr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   r    r!   r"   r#   pip._internal.utils.temp_dirr$   pip._internal.utils.virtualenvr%   r&   pip._internal.wheel_builderr'   r(   r  r   r)   r  r  r   r  r   r   r   r`   r`   r`   ra   <module>   s        S     	    >