U
    „}agÁG  ã                   @   sÞ  d 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	m
Z
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 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& ddl'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9 e	�r^ddl:m;Z; e <e=¡Z>ed dœdd„Z?G dd„ deƒZ@G d d!„ d!ee@ƒZAe7jBe7jCe7jDgZEddœd"d#„ZFe
e
d$œd%d&„ZGG d'd(„ d(eAƒZHdS ))a  Contains the Command base classes that depend on PipSession.

The classes in this module are in a separate module so the commands not
needing download / PackageFinder capability don't unnecessarily import the
PackageFinder machinery and all its vendored dependencies, etc.
é    N)Úpartial)ÚValues)ÚTYPE_CHECKINGÚAnyÚListÚOptionalÚTuple)Ú
WheelCache)Ú
cmdoptions)ÚCommand)ÚCommandContextMixIn)ÚCommandErrorÚPreviousBuildDirError)ÚLinkCollector)ÚPackageFinder)ÚSelectionPreferences)ÚTargetPython)Ú
PipSession)ÚBuildTracker)ÚRequirementPreparer)Úinstall_req_from_editableÚinstall_req_from_lineÚ#install_req_from_parsed_requirementÚinstall_req_from_req_string)Úparse_requirements)ÚInstallRequirement)ÚBaseResolver)Úpip_self_version_check)ÚTempDirectoryÚTempDirectoryTypeRegistryÚtempdir_kinds)Úrunning_under_virtualenv)Ú
SSLContextr"   ©Úreturnc               
   C   sŽ   t jdk rtdƒ‚zdd l} W n  tk
r>   t d¡ Y d S X zddlm} W n0 tk
r€ } ztd|› �ƒ‚W 5 d }~X Y nX | 	| j
¡S )N)é   é
   z9The truststore feature is only available for Python 3.10+r   z1Disabling truststore since ssl support is missing)Ú
truststorez'The truststore feature is unavailable: )ÚsysÚversion_infor   ÚsslÚImportErrorÚloggerÚwarningÚpip._vendorr'   r"   ÚPROTOCOL_TLS_CLIENT)r*   r'   Úe© r1   úU/var/www/html/publicvenv/lib/python3.8/site-packages/pip/_internal/cli/req_command.pyÚ_create_truststore_ssl_context2   s    

 r3   c                       sr   e Zd ZdZddœ‡ fdd„Zeeeee	  dœdd„ƒZ
eedœd	d
„Zdeee ee eedœdd„Z‡  ZS )ÚSessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    Nr#   c                    s   t ƒ  ¡  d | _d S ©N)ÚsuperÚ__init__Ú_session)Úself©Ú	__class__r1   r2   r7   J   s    
zSessionCommandMixin.__init__©Úoptionsr$   c                 C   sL   g }t |ddƒs*t |ddƒ}|r*| |¡ t |ddƒ}|rD| |¡ |pJdS )z7Return a list of index urls from user-provided options.Úno_indexFÚ	index_urlNÚextra_index_urls)ÚgetattrÚappendÚextend)Úclsr=   Ú
index_urlsÚurlÚurlsr1   r1   r2   Ú_get_index_urlsN   s    

z#SessionCommandMixin._get_index_urlsc                 C   s0   | j dkr*|  |  |¡¡| _ | j dk	s*t‚| j S )zGet a default-managed session.N)r8   Úenter_contextÚ_build_sessionÚAssertionError)r9   r=   r1   r1   r2   Úget_default_session\   s    
z'SessionCommandMixin.get_default_sessionF)r=   ÚretriesÚtimeoutÚfallback_to_certifir$   c                 C   sø   |j }|rtj |¡st‚d|jkrPz
tƒ }W qT tk
rL   |sD‚ d }Y qTX nd }t|rhtj 	|d¡nd |d k	rv|n|j
|j|  |¡|d�}|jrœ|j|_|jrª|j|_|js´|rÈ|d k	rÀ|n|j|_|jrÞ|j|jdœ|_|j |j_|j|j_|S )Nr'   zhttp-v2)ÚcacherM   Útrusted_hostsrE   Ússl_context)ÚhttpÚhttps)Ú	cache_dirÚosÚpathÚisabsrK   Úfeatures_enabledr3   Ú	Exceptionr   ÚjoinrM   rQ   rH   ÚcertÚverifyÚclient_certrN   ÚproxyÚproxiesÚno_inputÚauthZ	promptingÚkeyring_provider)r9   r=   rM   rN   rO   rU   rR   Úsessionr1   r1   r2   rJ   f   s<    

û	
þ
z"SessionCommandMixin._build_session)NNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   Úclassmethodr   r   r   ÚstrrH   r   rL   ÚintÚboolrJ   Ú__classcell__r1   r1   r:   r2   r4   D   s      ûúr4   c                   @   s    e Zd ZdZeddœdd„ZdS )ÚIndexGroupCommandz–
    Abstract base class for commands with the index_group options.

    This also corresponds to the commands that permit the pip version check.
    Nr<   c              	   C   sV   t |dƒst‚|js|jrdS | j|dtd|jƒdd�}|� t||ƒ W 5 Q R X dS )z€
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r>   Nr   é   T)rM   rN   rO   )ÚhasattrrK   Údisable_pip_version_checkr>   rJ   ÚminrN   r   )r9   r=   rd   r1   r1   r2   Úhandle_pip_version_check¤   s    
ø
z*IndexGroupCommand.handle_pip_version_check)re   rf   rg   rh   r   rs   r1   r1   r1   r2   rn   œ   s   rn   c                   C   sN   t ƒ r
dS ttdƒsdS tjdks,tjdkr0dS t ¡ dkr@dS t d¡ dS )züOutput a warning for sudo users on Unix.

    In a virtual environment, sudo pip still writes to virtualenv.
    On Windows, users may run pip as Administrator without issues.
    This warning only applies to Unix root users outside of virtualenv.
    NÚgetuidÚwin32Úcygwinr   zÔRunning pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv)r!   rp   rV   r(   Úplatformrt   r,   r-   r1   r1   r1   r2   Úwarn_if_run_as_rootÆ   s    
ÿrx   )Úfuncr$   c                    s6   t ddœdd„‰ tttt tt dœ‡ ‡fdd„}|S )zNDecorator for common logic related to managing temporary
    directories.
    N)Úregistryr$   c                 S   s   t D ]}|  |d¡ qd S )NF)ÚKEEPABLE_TEMPDIR_TYPESÚ
set_delete)rz   Útr1   r1   r2   Úconfigure_tempdir_registryé   s    z0with_cleanup.<locals>.configure_tempdir_registry)r9   r=   Úargsr$   c                    sR   | j d k	st‚|jrˆ | j ƒ zˆ| ||ƒW S  tk
rL   ˆ | j ƒ ‚ Y nX d S r5   )Útempdir_registryrK   Úno_cleanr   )r9   r=   r   ©r~   ry   r1   r2   Úwrapperí   s    

zwith_cleanup.<locals>.wrapper)r   ÚRequirementCommandr   r   r   r   rk   )ry   rƒ   r1   r‚   r2   Úwith_cleanupä   s      þr…   c                       sò   e Zd Zeeddœ‡ fdd„Zeeedœdd„ƒZe	de
eeeeeee eed	œ	d
d„ƒZe	deeeee eeeeeee eeedf  edœdd„ƒZee eeeee dœdd„Zeeddœdd„ƒZdeeee ee edœdd„Z‡  ZS )r„   N)r   Úkwr$   c                    s"   t ƒ j||Ž | j t ¡ ¡ d S r5   )r6   r7   Úcmd_optsÚ
add_optionr
   r�   )r9   r   r†   r:   r1   r2   r7     s    zRequirementCommand.__init__r<   c                 C   s   d| j krdS dS )zEDetermines which resolver should be used, based on the given options.zlegacy-resolverÚlegacyÚ
resolvelib)Údeprecated_features_enabled©r=   r1   r1   r2   Údetermine_resolver_variant  s    
z-RequirementCommand.determine_resolver_variantr   )	Útemp_build_dirr=   Úbuild_trackerrd   ÚfinderÚuse_user_siteÚdownload_dirÚ	verbosityr$   c	                 C   sŒ   |j }	|	dk	st‚d}
|  |¡}|dkrBd|jk}|r^t d¡ nd}
d}d|jkr^t d¡ t|	|j||j|j	|||j
||j||||
d�S )	zQ
        Create a RequirementPreparer instance for the given parameters.
        NFrŠ   z	fast-depszÊpip is using lazily downloaded wheels using HTTP range requests to obtain dependency information. This experimental feature is enabled through --use-feature=fast-deps and it is not ready for production.Tz;fast-deps has no effect when used with the legacy resolver.)Z	build_dirÚsrc_dirr’   Úbuild_isolationÚcheck_build_depsr�   rd   Úprogress_barr�   Úrequire_hashesr‘   Ú
lazy_wheelr“   Úlegacy_resolver)rW   rK   r�   rY   r,   r-   r   r”   r•   r–   r—   r˜   )rD   rŽ   r=   r�   rd   r�   r‘   r’   r“   Ztemp_build_dir_pathrš   Úresolver_variantr™   r1   r1   r2   Úmake_requirement_preparer  s@    

ÿ
ÿòz,RequirementCommand.make_requirement_preparerFTúto-satisfy-only.)Úpreparerr�   r=   Úwheel_cacher‘   Úignore_installedÚignore_requires_pythonÚforce_reinstallÚupgrade_strategyÚ
use_pep517Úpy_version_infor$   c                 C   s†   t t|j|
d�}|  |¡}|dkrTddl}|jjjjj	||||||j
||||	|d�S ddl}|jjjjj	||||||j
||||	|d�S )zF
        Create a Resolver instance for the given parameters.
        )Úisolatedr¤   rŠ   r   N)rž   r�   rŸ   Úmake_install_reqr‘   Úignore_dependenciesr    r¡   r¢   r£   r¥   )r   r   Úisolated_moder�   Z,pip._internal.resolution.resolvelib.resolverÚ	_internalÚ
resolutionrŠ   ÚresolverZResolverr¨   Z(pip._internal.resolution.legacy.resolverr‰   )rD   rž   r�   r=   rŸ   r‘   r    r¡   r¢   r£   r¤   r¥   r§   r›   Úpipr1   r1   r2   Úmake_resolverE  sF    ý
õõz RequirementCommand.make_resolver)r   r=   r�   rd   r$   c                 C   sv  g }|j D ]6}t|d|||d�D ]}t||jdd�}| |¡ q q
|D ].}	t|	d|j|jdt|ddƒd�}| |¡ qF|jD ],}	t	|	d|j|jt|ddƒd�}| |¡ q||j
D ]L}t||||d	�D ]6}t||j|jd|jrè|j d¡ndd
�}| |¡ qÄq°tdd„ |D ƒƒ�rd|_|�sr|j�sr|j
�srd| ji}
|j�rbtdjf t|
d |j¡d�Žƒ‚ntdjf |
Žƒ‚|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)Z
constraintr�   r=   rd   F)r¦   Úuser_suppliedNÚconfig_settings)Ú
comes_fromr¦   r¤   r¯   r°   )r¯   r¦   r¤   r°   )r�   r=   rd   )r¦   r¤   r¯   r°   c                 s   s   | ]}|j V  qd S r5   )Zhas_hash_options)Ú.0Úreqr1   r1   r2   Ú	<genexpr>À  s     z6RequirementCommand.get_requirements.<locals>.<genexpr>ÚnamezXYou must give at least one requirement to {name} (maybe you meant "pip {name} {links}"?)ú )ÚlinkszHYou must give at least one requirement to {name} (see "pip help {name}"))Úconstraintsr   r   r©   rB   r   r¤   rA   Ú	editablesr   Úrequirementsr=   ÚgetÚanyr˜   rµ   Ú
find_linksr   ÚformatÚdictr[   )r9   r   r=   r�   rd   rº   ÚfilenameZ
parsed_reqZ
req_to_addr³   Úoptsr1   r1   r2   Úget_requirements€  s†    

û
ý
ú

û
   ÿ
ÿù	
þÿÿÿz#RequirementCommand.get_requirements)r�   r$   c                 C   s    | j }| ¡ }|rt |¡ dS )zE
        Trace basic information about the provided objects.
        N)Úsearch_scopeZget_formatted_locationsr,   Úinfo)r�   rÃ   Ú	locationsr1   r1   r2   Útrace_basic_infoÔ  s    z#RequirementCommand.trace_basic_info)r=   rd   Útarget_pythonr¡   r$   c                 C   s6   t j||d�}td|j|j|j|d�}tj|||d�S )zÛ
        Create a package finder appropriate to this requirement command.

        :param ignore_requires_python: Whether to ignore incompatible
            "Requires-Python" values in links. Defaults to False.
        rŒ   T)Zallow_yankedÚformat_controlÚallow_all_prereleasesÚprefer_binaryr¡   )Úlink_collectorÚselection_prefsrÇ   )r   Úcreater   rÈ   ÚprerÊ   r   )r9   r=   rd   rÇ   r¡   rË   rÌ   r1   r1   r2   Ú_build_package_finderß  s    ûýz(RequirementCommand._build_package_finder)Nr   )NFTFFr�   NN)NN)re   rf   rg   r   r7   Ústaticmethodr   rj   r�   ri   r   r   r   r   rl   r   rk   r   rœ   r	   r   r   r®   r   r   rÂ   rÆ   r   rÏ   rm   r1   r1   r:   r2   r„      sr   	  ÷ö6        ôó<úT  ûúr„   )Irh   ÚloggingrV   r(   Ú	functoolsr   Úoptparser   Útypingr   r   r   r   r   Úpip._internal.cacher	   Úpip._internal.clir
   Úpip._internal.cli.base_commandr   Ú!pip._internal.cli.command_contextr   Úpip._internal.exceptionsr   r   Zpip._internal.index.collectorr   Z"pip._internal.index.package_finderr   Z$pip._internal.models.selection_prefsr   Ú"pip._internal.models.target_pythonr   Zpip._internal.network.sessionr   Ú,pip._internal.operations.build.build_trackerr   Z pip._internal.operations.preparer   Zpip._internal.req.constructorsr   r   r   r   Zpip._internal.req.req_filer   Úpip._internal.req.req_installr   Zpip._internal.resolution.baser   Z!pip._internal.self_outdated_checkr   Úpip._internal.utils.temp_dirr   r   r    Úpip._internal.utils.virtualenvr!   r*   r"   Ú	getLoggerre   r,   r3   r4   rn   Ú	BUILD_ENVÚEPHEM_WHEEL_CACHEÚ	REQ_BUILDr{   rx   r…   r„   r1   r1   r1   r2   Ú<module>   sL   
X$ý