a
    e0h!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rd 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 )NTbinary)
use_pep517r   nameget_allowed_formats)reqcanonical_nameallowed_formatsformat_control L/var/www/auris/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   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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_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.)r:   actionr=   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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<   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-compilestore_falsez.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           )         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
st st dkrd|_ |j
rd|_ tj|j|_|jpg }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|j45 D }t6||dg g d\}}dd |D }|rt7d8d9||D ]}|j,sd|_:q|;|}d }|j< o|j=}|r| >|}|j?}|jrd}t@||||j||j	||j |jAd	}tB|j ||j|j	|jd}tCD|} |jEtFGd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|!}%|%rtNd#|% 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)check_targetr   FzUsing %s)rC   r8   rB   isolated_modez=Target path exists but is not a directory, will not continue.target)kind)optionssessiontarget_pythonrX   install)deleterl   globally_managed)temp_build_dirrm   req_trackerrn   finderr>   )
preparerru   rm   wheel_cacher>   rI   rX   rH   rE   r+   )check_supported_wheelspip)modifying_pipc                    s   g | ]}t | r|qS r3   )r    .0rr5   r3   r4   
<listcomp>n  s
   z&InstallCommand.run.<locals>.<listcomp>)rw   verifybuild_optionsr\   c                 S   s   g | ]}|j r|jqS r3   )r+   r,   r{   r3   r3   r4   r     s   zPCould not build wheels for {} which use PEP 517 and cannot be installed directlyz, i   )roothomeprefixrL   r>   	pycompile)userr   r   r   isolatedr,   )key)working_set-)resolver_variant zSuccessfully installed %s   )exc_info)Vr>   r8   r   r   check_install_build_globalrD   rE   check_dist_restrictionpython_versionrC   rA   r)   osgeteuidpathabspathsrc_dirr[   loggerdebugr   decide_user_installrB   rj   rI   existsisdirr   enter_contextr\   get_default_sessionr   _build_package_finderrX   r   	cache_dirr2   r   no_cleanget_requirements'reject_location_related_install_optionsmake_requirement_preparermake_resolverrH   r+   trace_basic_inforesolveget_requirementKeyErrorsatisfied_byr   r6   rP   valuesr   r   formatjoinlegacy_install_reasonget_installation_orderignore_dependenciesrM   _determine_conflictsrL   r   rJ   get_lib_location_guessesr   
WorkingSetsortoperator
attrgetterr,   r   	Exceptionappend_warn_about_conflictsdetermine_resolver_variantr   EnvironmentError	verbositycreate_env_error_messageerrorr   _handle_target_dirr   ))rf   rm   argsrE   python_versionsr[   target_temp_dirtarget_temp_dir_pathr\   rn   ro   ru   rw   rt   	directoryreqsrv   resolverrequirement_setpip_reqrz   reqs_to_build_build_failurespep517_build_failure_namesr}   
to_install	conflictsshould_warn_about_conflictsrL   	installedlib_locationsr   itemsresultiteminstalled_versioninstalled_descr   show_tracebackmessager3   r~   r4   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rtj||
 t fdd|d d D rqtj||
}tj|r6|st	
d	| qtj|rt	
d
| qtj|r,t| n
t| ttj|	|
| qqd 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.zTarget 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)rf   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)rf   r   r3   r3   r4   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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.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,   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   r   criticalr   )rf   conflict_detailsr   package_setmissingconflictingpartsproject_namer   
dependencyr   r   r   r.   r3   r3   r4   r   (  sH    z$InstallCommand._warn_about_conflictsN)__name__
__module____qualname____doc__usagerh   r
   r   r   r   r   r3   r3   r3   r4   r7   A   s    
 v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   ^  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   m  s   z)site_packages_writable.<locals>.<genexpr>r   r   )allsetr   r
  r3   r3   r4   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
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   r   r   r   r   siteENABLE_USER_SITEr  info)r>   rC   r8   rB   rj   r3   r3   r4   r   s  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 )zIf 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 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   r   keysr   r   )rP   rm   r  	offendersr   r[   location_optionsr3   r3   r4   r     s4    
r   c                 C   s   g }| d |s,| d | t|  n
| d |d  d7  < | jtjkrd}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)N
__future__r   r  loggingr   r   r   r  optparser   pip._vendorr   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.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(   r)   	getLoggerr  r   r6   r7   r   r  r   r   r   r3   r3   r3   r4   <module>   sn   
    "     

    
<*