B
    žHeq  ã               @   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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.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZA e3eBƒZCG dd„ deƒZDd(eEeeF eeF eEeeF e
eF dœdd„ZGeeF eEeEdœd d!„ZHd)eeE eeF eeF eeF eEeEd"œd#d$„ZIeJeEeEeFd%œd&d'„ZKdS )*é    N)ÚSUPPRESS_HELPÚValues)ÚListÚOptional)Ú
print_json)Ú
WheelCache)Ú
cmdoptions)Úmake_target_python)ÚRequirementCommandÚwarn_if_run_as_rootÚ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Ú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_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,   Úmetavarr-   r.   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+   r.   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-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_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,   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   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_pep517Z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]   úr/var/www/downstreamdata.science/rtclock/rtclock-venv/lib/python3.7/site-packages/pip/_internal/commands/install.pyÚadd_optionsH   sâ    

zInstallCommand.add_options)ÚoptionsÚargsr(   c       *      C   sä  |j r|jd k	rtdƒ‚|jo"|j oB|jd koB|jd koB|jd k}|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¡rètj |j¡sètdƒ‚tdd	}|j}|  |¡ |jpg }|  |¡}t|ƒ}	| j|||	|jd
}
|  tƒ ¡}t|j  ddd}y
|  !|||
|¡}t"||ƒ t#|j$ƒ}x|D ]}d|_%q€W | j&|||||
|j | j'd}| j(||
|||j |j|j|j)||j*d
}|  +|
¡ |j,||j d}|jrPt-|j.ƒ}|jdkrt/| 0¡ d n2t1|jddd}t2j3| 0¡ |ddd W d Q R X |jr˜| 4¡  t5dd„ |j.D ƒƒ}|r”t6dd 7dd„ |D ƒ¡ƒ t8S y| 9d¡}W n t:k
rÀ   d}Y nX |j;d k}t<|d dd „ |j= >¡ D ƒ}t?||dg |d!\}}|r$t@d" Ad# 7d$d„ |D ƒ¡¡ƒ‚| B|¡}d }|jC o@|jD}|rR|  E|¡}|jF}|jsh|jrld}tG|||j||j||j |jHd%}tI|j ||j|j|jd&} tJ| ƒ}!|jKtL Md'¡d( g }"x^|D ]V}#|#jN}$y(|! O|$¡}%|%d k	rú|$› d|%jP› }$W n tQk
r   Y nX |" R|$¡ qÊW |d k	rB| jS||  T|¡d) d 7|"¡}&|&r\t6d*|&ƒ W nJ tUk
r¨ }' z*| j'd+k}(tV|'|(|j ƒ})tjW|)|(d, tXS d }'~'X Y nX |jrÎ|s¼tY‚|  Z|j||j	¡ |j[d-kràt\ƒ  t8S ).Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Úcheck_targetzUsing %s)r5   r/   r4   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)r`   ÚsessionÚtarget_pythonrJ   Úinstall)Údeletere   Úglobally_managed)Útemp_build_dirr`   Úbuild_trackerrf   Úfinderr2   Ú	verbosity)
Úpreparerrm   r`   Úwheel_cacher2   r;   rJ   r:   r7   rL   )Ú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]   r^   ú	<genexpr>Š  s   z%InstallCommand.run.<locals>.<genexpr>zWould install %sú c             s   s   | ]}d   |¡V  qdS )rr   N)Újoin)r|   Úitemr]   r]   r^   r~     s    Úpip)Úmodifying_pipc             S   s   g | ]}t |ƒr|‘qS r]   )r&   )r|   r}   r]   r]   r^   ú
<listcomp>Ÿ  s   z&InstallCommand.run.<locals>.<listcomp>)rp   ÚverifyÚbuild_optionsrP   zYCould not build wheels for {}, which is required to install pyproject.toml-based projectsz, c             s   s   | ]}|j V  qd S )N)ry   )r|   r}   r]   r]   r^   r~   °  s    )ÚrootÚhomeÚprefixr=   r2   Ú	pycompile)Úuserrˆ   r‡   r‰   Úisolatedry   )Úkey)Úresolver_variantzSuccessfully installed %sé   )Úexc_infoÚwarn)]r2   r/   r   r*   r?   r4   r5   rN   r   r6   r7   r   Úcheck_dist_restrictionÚloggerÚverboser   Údecide_user_installrc   r;   ÚosÚpathÚabspathÚexistsÚisdirr"   Úenter_contextrP   Úget_default_sessionr	   Ú_build_package_finderrJ   r   Úno_cleanÚget_requirementsr   r   Ú	cache_dirÚpermit_editable_wheelsÚmake_requirement_preparerrn   Úmake_resolverr:   rL   Útrace_basic_infoÚresolver   Zrequirements_to_installr   Úto_dictÚopenÚjsonÚdumpZ#warn_legacy_versions_and_specifiersÚsortedr!   r€   r   Úget_requirementÚKeyErrorÚsatisfied_byr    rC   Úvaluesr%   r   ÚformatÚget_installation_orderÚignore_dependenciesr>   Ú_determine_conflictsr=   r   r<   Úget_lib_location_guessesr   ÚsortÚoperatorÚ
attrgetterry   Úget_distributionrz   Ú	ExceptionÚappendÚ_warn_about_conflictsÚdetermine_resolver_variantÚOSErrorÚcreate_os_error_messageÚerrorr   ÚAssertionErrorÚ_handle_target_dirrV   r   )*r[   r`   ra   Z#installing_into_current_environmentr7   Útarget_temp_dirÚtarget_temp_dir_pathrP   rf   rg   rm   rl   Ú	directoryÚreqsrp   Úreqro   ÚresolverÚrequirement_setÚreportÚfZwould_install_itemsÚpip_reqrƒ   Úreqs_to_buildÚ_Úbuild_failuresÚ
to_installÚ	conflictsÚshould_warn_about_conflictsr=   Ú	installedÚlib_locationsÚenvÚitemsÚresultr   Úinstalled_distÚinstalled_descr¾   Úshow_tracebackÚmessager]   r]   r^   Úrun	  sL   













 














zInstallCommand.run)r/   rÁ   r6   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 ]Ò}	xÌt 	|	¡D ]¾}
|	|krÆtj 
||
¡‰ t‡ fdd„|d d… D ƒƒrÆqŒtj 
||
¡}tj |¡r4|sôt d|¡ qŒtj |¡rt d|¡ qŒtj |¡r*t |¡ n
t |¡ t tj 
|	|
¡|¡ qŒW q|W d S )NÚ )rˆ   c             3   s   | ]}|  ˆ ¡V  qd S )N)Ú
startswith)r|   Ús)Úddirr]   r^   r~      s    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Úplatlibrs   r–   r™   r¹   Úlistdirr€   Úanyr“   ÚwarningÚislinkrš   ÚshutilÚrmtreeÚremoveÚmove)r[   r/   rÁ   r6   Úlib_dir_listÚschemeÚpurelib_dirÚplatlib_dirÚdata_dirÚlib_dirr   Útarget_item_dirr]   )rÞ   r^   rÀ     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)r[   rÎ   r]   r]   r^   r²   ;  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rÔd
ndd}
|  |
¡ q°W q–W t 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2020-resolverz§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   z@{name} {version} requires {requirement}, which is not installed.r   )ry   rz   Úrequirementzg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.Úyouzyou'll)ry   rz   rô   Údep_nameÚdep_versionrõ   Ú
)r¹   r¿   r¯   r“   Úcriticalr€   )r[   rò   rŽ   Úpackage_setÚmissingÚconflictingÚpartsÚproject_namerz   Ú
dependencyrÙ   rö   r÷   rÅ   r]   r]   r^   rº   G  s<    

z$InstallCommand._warn_about_conflicts)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úusager_   r   r   r   ÚstrÚintrÚ   r"   ÚboolrÀ   r   r   r   r²   rº   r]   r]   r]   r^   r'   4   s    B }5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]   r^   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|   Údr]   r]   r^   r~   ’  s   z)site_packages_writable.<locals>.<genexpr>)r‡   rŒ   )ÚallÚsetr³   )r‡   rŒ   r]   r]   r^   Úsite_packages_writable  s    r  )r2   r5   r/   r4   rc   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
r–t  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)r2   r5   r/   r4   rc   r]   r]   r^   r•   —  s2    




r•   )r¾   rØ   Úusing_user_siter(   c             C   sÎ   g }|  d¡ |s,|  d¡ |  t| ƒ¡ n
|  d¡ |d  d7  < | jtjkrŽd}d}tƒ sz|sz| |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  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  ÚerrnoÚEACCESr#   ÚextendÚlowerr   ÚENOENTÚfilenameÚlenr€   Ústrip)r¾   rØ   r  rý   Úuser_option_partÚpermissions_partr]   r]   r^   r½   Ô  s0    





r½   )FNNFN)NNNF)Lr  r¨   rµ   r–   ræ   r  Úoptparser   r   Útypingr   r   Úpip._vendor.richr   Úpip._internal.cacher   Zpip._internal.clir   Zpip._internal.cli.cmdoptionsr	   Úpip._internal.cli.req_commandr
   r   r   Úpip._internal.cli.status_codesr   r   Úpip._internal.exceptionsr   r   Úpip._internal.locationsr   Úpip._internal.metadatar   Z(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!   Ú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]   r^   Ú<module>   s`       O    	   8