B
    c{                 @   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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 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/ d dl0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZGmHZH d dlImJZJmKZKmLZL e>eMZNe&eJdddZOG d d! d!eZPd2eQeeR eeR eQeeR eeR d#d$d%ZSeeR eQeQd&d'd(ZTd3eeQ eeR eeR eeR eQeQd)d*d+ZUee1 eeeR  dd,d-d.ZVeWeQeQeRd/d0d1ZXdS )4    N)SUPPRESS_HELPValues)IterableListOptional)canonicalize_name)
print_json)
WheelCache)
cmdoptions)make_target_python)RequirementCommandwarn_if_run_as_rootwith_cleanup)ERRORSUCCESS)CommandErrorInstallationError)
get_scheme)get_environment)FormatControl)InstallationReport)get_build_tracker)ConflictDetailscheck_install_conflicts)install_given_reqs)InstallRequirementLegacySetupPyOptionsCheckModecheck_legacy_setup_py_options)WINDOWS)#LegacyInstallReasonFailedBdistWheel
deprecated)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)BdistWheelAllowedPredicatebuild should_build_for_install_command)format_controlreturnc                s   t td fdd}|S )N)reqr/   c                s    t | jp
d} |}d|kS )N binary)r   nameget_allowed_formats)r0   canonical_nameZallowed_formats)r.    O/var/www/cleansys/lib/python3.7/site-packages/pip/_internal/commands/install.pycheck_binary_allowedB   s    
z;get_check_bdist_wheel_allowed.<locals>.check_binary_allowed)r   bool)r.   r8   r6   )r.   r7   get_check_bdist_wheel_allowed?   s    r:   c               @   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)r/   c             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@   rA   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>   rA   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@   choicesrA   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?   rA   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config_settingsinstall_optionsglobal_options	no_binaryonly_binaryprefer_binaryrequire_hashesprogress_barroot_user_actionmake_option_groupindex_groupparserinsert_option_group)selfZ
index_optsr6   r6   r7   add_options^   s    
zInstallCommand.add_options)optionsargsr/   c       ,         s*  |j r|jd k	rtdd}|jr(|j}tj|dd |jp>g }t	dt
  t|j |j|j|j|jd|_ d }d }|jrd|_tj|j|_tj|jrtj|jstdtdd	}|j}| | |jpg }| |}t|}	| j|||	|jd
}
| t }t|j ddd}y| |||
|}t||t j! d|j"krVt#|j$}n*|j%j&rrt'dddddd t#|j$|j%}x|D ]}d|_(qW t)||j | j*|||||
|j | j+d}| j,||
|||j |j|j|j-||j.d
}| /|
 |j0||j d}|j1rlt2d t3|j4}|j1dkr:t5|6 d n2t7|j1ddd}t8j9|6 |ddd W d Q R X |j:rt;dd  |j4D }|rt<d!d"=d#d  |D  t>S y|?d$}W n t@k
r   d}Y nX |jAd k}tB|d% tC|
j%  fd&d'|jDE D }tF||dg |d(\}}d)d' |D }|rJtGd*Hd+=|x|D ]}|j.sPtI|_JqPW |K|}d }|jL o|jM}|r| N|}|jO} |js|jrd} tP||||j||j| |j |jQd,	}!tR|j ||j|j|jd-}"tS|"}#|!jTtUVd.d/ g }$x^|!D ]V}%|%jW}&y(|#X|&}'|'d k	r@|& d|'jY }&W n tZk
rX   Y nX |$[|& qW |d k	r| j\|| ]|d0 d"=|$}(|(rt<d1|( W nJ t^k
r }) z*| j+d2k}*t_|)|*|j }+tj`|+|*d3 taS d })~)X Y nX |jr|stb| c|j||j |jdd4kr&te  t>S )5Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)check_targetzUsing %s)rH   rB   rG   isolated_modez=Target path exists but is not a directory, will not continue.target)kind)rp   sessiontarget_pythonr\   install)deleteru   globally_managedzno-binary-enable-wheel-cachez--no-binary currently disables reading from the cache of locally built wheels. In the future --no-binary will not influence the wheel cache.z to use the --no-cache-dir optioni,  z23.1)reasonreplacementfeature_flagissuegone_in)Ztemp_build_dirrp   build_trackerrv   finderrE   	verbosity)
preparerr   rp   wheel_cacherE   rM   r\   rL   rJ   r^   )Zcheck_supported_wheelszu--report is currently an experimental option. The output format may change in a future release without prior warning.-)datawzutf-8)encoding   F)indentensure_asciic             s   s"   | ]}|j d  |j d fV  qdS )r3   versionN)metadata).0rr6   r6   r7   	<genexpr>  s   z%InstallCommand.run.<locals>.<genexpr>zWould install %s c             s   s   | ]}d  |V  qdS )r   N)join)r   itemr6   r6   r7   r     s    pip)modifying_pipc                s   g | ]}t | r|qS r6   )r-   )r   r   )check_bdist_wheel_allowedr6   r7   
<listcomp>  s   z&InstallCommand.run.<locals>.<listcomp>)r   verifybuild_optionsrc   c             S   s   g | ]}|j r|jqS r6   )r^   r3   )r   r   r6   r6   r7   r     s    zYCould not build wheels for {}, which is required to install pyproject.toml-based projectsz, )roothomeprefixrO   rE   Z	pycompile)userr   r   r   isolatedr3   )key)resolver_variantzSuccessfully installed %s   )exc_infowarn)frE   rB   r   rI   rJ   r
   check_dist_restrictionrb   loggerverboser%   decide_user_installrH   rG   rs   rM   ospathabspathexistsisdirr(   enter_contextrc   Zget_default_sessionr   Z_build_package_finderr\   r   no_cleanZget_requirementsr   r   INSTALLfeatures_enabledr	   	cache_dirr.   rd   r    Zpermit_editable_wheels'reject_location_related_install_optionsZmake_requirement_preparerr   Zmake_resolverrL   r^   Ztrace_basic_inforesolverQ   warningr   Zrequirements_to_installr   to_dictopenjsondumpr=   sortedr'   r   r   get_requirementKeyErrorZsatisfied_byr&   r:   rU   valuesr,   r   formatr   Zlegacy_install_reasonZget_installation_orderignore_dependenciesrP   _determine_conflictsrO   r   rN   get_lib_location_guessesr   sortoperator
attrgetterr3   get_distributionr   	Exceptionappend_warn_about_conflictsZdetermine_resolver_variantOSErrorcreate_os_error_messageerrorr   AssertionError_handle_target_dirri   r   ),rn   rp   rq   rJ   rb   target_temp_dirZtarget_temp_dir_pathrc   rv   rw   r   r   	directoryreqsr   r0   r   ZresolverZrequirement_setZreportfZwould_install_itemsZpip_reqr   Zreqs_to_build_Zbuild_failuresZpep517_build_failure_namesr   
to_installZ	conflictsZshould_warn_about_conflictsrO   	installedZlib_locationsenvitemsresultr   Zinstalled_distZinstalled_descr   show_tracebackmessager6   )r   r7   run  sf   











 
















zInstallCommand.run)rB   r   rI   r/   c                sV  t | g }td|jd}|j}|j}|j}tj|rB|| tj|r`||kr`|| tj|rv|| x|D ]}	xt	|	D ]}
|	|krtj
||
 t fdd|d d D rqtj
||
}tj|r4|std| qtj|rtd| qtj|r*t| n
t| ttj
|	|
| qW q|W d S )Nr1   )r   c             3   s   | ]}|  V  qd S )N)
startswith)r   s)ddirr6   r7   r   K  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platlibr   r   r   r   listdirr   anyr   r   islinkr   shutilrmtreeremovemove)rn   rB   r   rI   Zlib_dir_listschemeZpurelib_dirZplatlib_dirZdata_dirlib_dirr   Ztarget_item_dirr6   )r   r7   r   0  sD    




z!InstallCommand._handle_target_dir)r   r/   c             C   s,   yt |S  tk
r&   td d S X 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)rn   r   r6   r6   r7   r   f  s    z#InstallCommand._determine_conflicts)conflict_detailsr   r/   c          
   C   s  |\}\}}|s|sd S g }|dkr0| d n|dks<t| d xH|D ]@}|| d }x.|| D ]"}	dj|||	d d}
| |
 qfW qLW x\|D ]T}|| d }xB|| D ]6\}}}d	j||||||dkrd
ndd}
| |
 qW qW t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   )r3   r   requirementzg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.youzyou'll)r3   r   r   dep_namedep_versionr   
)r   r   r   r   criticalr   )rn   r   r   Zpackage_setmissingconflictingpartsproject_namer   
dependencyr   r   r   r0   r6   r6   r7   r   r  s<    

z$InstallCommand._warn_about_conflicts)__name__
__module____qualname____doc__usagero   r   r   r   strintr   r(   r9   r   r   r   r   r   r   r6   r6   r6   r7   r;   J   s    =  5r;   F)r   r   r   r   r   r/   c             C   s    t d| ||||d}|j|jgS )Nr1   )r   r   r   r   r   )r   r   r   )r   r   r   r   r   r   r6   r6   r7   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 )N)r"   )r   dr6   r6   r7   r     s   z)site_packages_writable.<locals>.<genexpr>)r   r   )allsetr   )r   r   r6   r6   r7   site_packages_writable  s    r   )rE   rH   rB   rG   rs   r/   c             C   s   | dk	r| st d dS | rF|r*tdt r8tdt d dS | dksRt|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 disabled)r   r   z0Non-user install because site-packages writeablezMDefaulting to user installation because normal site-packages is not writeable)
r   debugr   r*   r   r   siteENABLE_USER_SITEr   info)rE   rH   rB   rG   rs   r6   r6   r7   r     s2    




r   )rU   rp   r/   c             C   s   t t tt ddd}g }x8| D ]0}|j}t|}|r"|d|| | q"W |r~t|}|r~|d||  |sd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.
    )option_namesr/   c             S   s   dd | D S )Nc             S   s   g | ]}d  |ddqS )z--{}r   r   )r   replace)r   r3   r6   r6   r7   r     s    zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r6   )r  r6   r6   r7   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   rb   r!   r   r   keysr   r   )rU   rp   r  Z	offendersr   rb   Zlocation_optionsr6   r6   r7   r     s&    
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
r1   )r   r   errnoZEACCESr)   extendlowerr   ENOENTfilenamelenr   strip)r   r   r	  r   Zuser_option_partZpermissions_partr6   r6   r7   r   &  s0    





r   )FNNFN)NNNF)Yr  r   r   r   r   r  optparser   r   typingr   r   r   Zpip._vendor.packaging.utilsr   pip._vendor.richr   Zpip._internal.cacher	   Z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.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   r   r   pip._internal.utils.compatr   pip._internal.utils.deprecationr   r    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   r:   r;   r9   r   r   r   r   r   r   r   r6   r6   r6   r7   <module>   sp   	    d    	   8&