o
    1cl                     @   s~  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
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 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%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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZAmBZB e4eCZDde#de@fddZEG dd deZF	 			 	d:d!eGd"eeH d#eeH d$eGd%eeH de
eH fd&d'ZId#eeH d$eGdeGfd(d)ZJ				 d;d*eeG d+eeH d,eeH d-eeH d.eGdeGfd/d0ZKd1e
e* d2ee
eH  ddfd3d4ZLd5eMd6eGd7eGdeHfd8d9ZNdS )<    N)SUPPRESS_HELPValues)IterableListOptional)canonicalize_name)
WheelCache)
cmdoptions)make_target_python)RequirementCommandwarn_if_run_as_rootwith_cleanup)ERRORSUCCESS)CommandErrorInstallationError)
get_scheme)get_environment)FormatControl)ConflictDetailscheck_install_conflicts)install_given_reqs)InstallRequirement)get_requirement_tracker)WINDOWS)parse_distutils_argstest_writable_dir)	getLogger)
ensure_dirget_pip_version(protect_pip_from_modification_on_windowswrite_output)TempDirectory)running_under_virtualenvvirtualenv_no_global)BinaryAllowedPredicatebuild should_build_for_install_commandformat_controlreturnc                    s   dt dtf fdd}|S )Nreqr*   c                    s    t | jpd} |}d|v S )N binary)r   nameget_allowed_formats)r+   canonical_nameZallowed_formatsr)    W/var/www/html/django/env/lib/python3.10/site-packages/pip/_internal/commands/install.pycheck_binary_allowed5   s   
z6get_check_binary_allowed.<locals>.check_binary_allowed)r   bool)r)   r4   r2   r1   r3   get_check_binary_allowed4   s   r6   c                   @   s   e Zd ZdZdZdddZededee	 de
fd	d
Zde	dededdfddZdee dee fddZdede	ddf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> ...r*   Nc                 C   sj  | 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 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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.)destmetavardefaulthelpz--useruse_user_site
store_truezInstall 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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-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:   r<   choicesr=   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 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   srcignore_requires_pythonno_build_isolation
use_pep517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)selfZ
index_optsr2   r2   r3   add_optionsQ   s   zInstallCommand.add_optionsoptionsargsc           )         s.  |j r|jd urtdt| d}|jr|j}tj|dd |jp$g }t	
dt  t|j |j|j|j|jd|_ d }d }|jrld|_tj|j|_tj|jr_tj|js_tdtdd	}|j}| | |jppg }| |}t|}	| j|||	|jd
}
t|j|j}| t  }t|j! ddd}z<| "|||
|}|D ]}d|_#qt$||j | j%|||||
|j | j&d}| j'||
|||j |j|j|j(||j)d
}| *|
 |j+||j d}z|,d}W n t-y   d}Y nw |j.d u }t/|d t0|
j  fdd|j12 D }t3||dg g d\}}dd |D }|r/t4d5d6||D ]
}|j)s:d|_7q1|8|}d }|j9 oJ|j:}|rS| ;|}|j<}|js^|jr`d}t=||||j||j||j |j>d	}t?|j ||j|j|jd}t@|} |jAtBCdd g }!|D ]*}"|"jD}#z| E|#}$|$d ur|# d|$jF }#W n
 tGy   Y nw |!H|# q|d ur| jI|| J|d d 6|!}%|%rtKd!|% W n( tLy }& z| j&d"k}'tM|&|'|j }(t	jN|(|'d# tOW  Y d }&~&S d }&~&ww |jr|s	J | P|j||j tQ  tRS )$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)rf   sessiontarget_pythonrU   install)deleterk   globally_managed)Ztemp_build_dirrf   req_trackerrl   finderr>   	verbosity)
preparerrr   rf   wheel_cacher>   rH   rU   rG   rE   rW   )Zcheck_supported_wheelspipF)modifying_pipc                    s   g | ]	}t | r|qS r2   )r(   .0rr4   r2   r3   
<listcomp>c  s    z&InstallCommand.run.<locals>.<listcomp>)ru   verifybuild_optionsrZ   c                 S   s   g | ]}|j r|jqS r2   )rW   r.   rx   r2   r2   r3   r|   s  s
    zYCould not build wheels for {}, which is required to install pyproject.toml-based projectsz, i   )roothomeprefixrJ   r>   Z	pycompile)userr   r   r   isolatedr.   )key-)resolver_variant zSuccessfully installed %s   )exc_info)Sr>   r8   r   r	   check_install_build_globalrD   rE   check_dist_restrictionrY   loggerverboser    decide_user_installrC   rB   ri   rH   ospathabspathexistsisdirr#   enter_contextrZ   Zget_default_sessionr
   Z_build_package_finderrU   r   	cache_dirr)   r   no_cleanZget_requirementsZpermit_editable_wheels'reject_location_related_install_optionsZmake_requirement_preparerrs   Zmake_resolverrG   rW   Ztrace_basic_inforesolveZget_requirementKeyErrorZsatisfied_byr!   r6   rN   valuesr'   r   formatjoinZlegacy_install_reasonZget_installation_orderignore_dependenciesrK   _determine_conflictsrJ   r   rI   get_lib_location_guessesr   sortoperator
attrgetterr.   get_distributionversion	Exceptionappend_warn_about_conflictsZdetermine_resolver_variantr"   OSErrorcreate_os_error_messageerrorr   _handle_target_dirr   r   ))rd   rf   rg   rE   rY   target_temp_dirZtarget_temp_dir_pathrZ   rl   rm   rr   ru   rq   	directoryZreqsr+   rt   ZresolverZrequirement_setZpip_reqrw   Zreqs_to_build_Zbuild_failuresZpep517_build_failure_namesrz   
to_installZ	conflictsZshould_warn_about_conflictsrJ   	installedZlib_locationsenvitemsresultitemZinstalled_distZinstalled_descr   show_tracebackmessager2   r{   r3   run   sh  





	
















zInstallCommand.runr8   r   rD   c                    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|rtd| qDtj|rt| nt| ttj
|	|
| qDq=d S )Nr,   )r   c                 3   s    | ]}|  V  qd S N)
startswith)ry   sZddirr2   r3   	<genexpr>  s    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platlibdatar   r   r   listdirr   anyr   warningislinkr   shutilrmtreeremovemove)rd   r8   r   rD   Zlib_dir_listschemeZpurelib_dirZplatlib_dirZdata_dirZlib_dirr   Ztarget_item_dirr2   r   r3   r     sL   



z!InstallCommand._handle_target_dirr   c                 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   r   r   	exception)rd   r   r2   r2   r3   r     s   
z#InstallCommand._determine_conflictsconflict_detailsr   c              
   C   s   |\}\}}|s|sd S g }|dkr| d n|dksJ | d |D ]}|| d }|| D ]}	dj|||	d d}
| |
 q1q%|D ](}|| d }|| D ]\}}}d	j||||||dkrdd
ndd}
| |
 qRqFtd| d S )NZlegacyzpip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.z2020-resolverzpip'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.r   )r.   r   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   r   criticalr   )rd   r   r   Zpackage_setmissingZconflictingpartsZproject_namer   
dependencyr   r   r   r+   r2   r2   r3   r     sL   z$InstallCommand._warn_about_conflicts)r*   N)__name__
__module____qualname____doc__usagere   r   r   r   strintr   r#   r5   r   r   r   r   r   r   r2   r2   r2   r3   r7   =   s:    
   g
6
r7   Fr   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   r2   r2   r3   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   )ry   dr2   r2   r3   r   c  s
    
z)site_packages_writable.<locals>.<genexpr>r   r   )allsetr   r   r2   r2   r3   site_packages_writableb  s   r   r>   rC   r8   rB   ri   c                 C   s   | dur| st d dS | r#|rtdt rtdt d dS | du s)J |s-|r4t d dS tjs>t d	 dS t||d
rKt 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)r>   rC   r8   rB   ri   r2   r2   r3   r   i  s8   




r   rN   rf   c                 C   s   dt t dtt fdd}g }| D ]}|j}t|}|r)|d|| | q|r>t|}|r>|d||  |sBdS tdd		|)
zIf any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    option_namesr*   c                 S   s   dd | D S )Nc                 S   s   g | ]}d  |ddqS )z--{}r   r   )r   replace)ry   r.   r2   r2   r3   r|     s    zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r2   )r   r2   r2   r3   format_options  s   z?reject_location_related_install_options.<locals>.format_optionsz{!r} from {}z{!r} from command lineNzLocation-changing options found in --install-option: {}. This is unsupported, use pip-level options like --user, --prefix, --root, and --target instead.z; )
r   r   r   rY   r   r   r   keysr   r   )rN   rf   r   Z	offendersr   rY   Zlocation_optionsr2   r2   r3   r     s0   r   r   r   using_user_sitec                 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r^| jtjkr^| j	r^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.
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   errnoZEACCESr$   extendlowerr   ENOENTfilenamelenr   strip)r   r   r   r   Zuser_option_partZpermissions_partr2   r2   r3   r     s>   






r   )FNNFN)NNNF)Or   r   r   r   r   optparser   r   typingr   r   r   pip._vendor.packaging.utilsr   Zpip._internal.cacher   pip._internal.clir	   Zpip._internal.cli.cmdoptionsr
   Zpip._internal.cli.req_commandr   r   r   pip._internal.cli.status_codesr   r   pip._internal.exceptionsr   r   pip._internal.locationsr   pip._internal.metadatar   #pip._internal.models.format_controlr   Zpip._internal.operations.checkr   r   Zpip._internal.reqr   Zpip._internal.req.req_installr   Zpip._internal.req.req_trackerr   pip._internal.utils.compatr   Z"pip._internal.utils.distutils_argsr   pip._internal.utils.filesystemr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r    r!   r"   pip._internal.utils.temp_dirr#   pip._internal.utils.virtualenvr$   r%   Zpip._internal.wheel_builderr&   r'   r(   r   r   r6   r7   r5   r   r   r   r   r   r   r   r2   r2   r2   r3   <module>   s    	    
	
=

'