U
    ƒIÀdH  ã                   @   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   sv   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}W n tk
rh   tdƒ‚Y nX | | j	¡S )N)é   é
   z9The truststore feature is only available for Python 3.10+r   z1Disabling truststore since ssl support is missingz]To use the truststore feature, 'truststore' must be installed into pip's current environment.)
ÚsysÚversion_infor   ÚsslÚImportErrorÚloggerÚwarningÚ
truststorer"   ÚPROTOCOL_TLS_CLIENT)r)   r-   © r/   úV/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/pip/_internal/cli/req_command.pyÚ_create_truststore_ssl_context2   s    

ÿ
r1   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__r/   r0   r5   M   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Úurlsr/   r/   r0   Ú_get_index_urlsQ   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)r6   Úenter_contextÚ_build_sessionÚAssertionError)r7   r;   r/   r/   r0   Ú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-   Úhttp)ÚcacherK   Útrusted_hostsrC   Ússl_context)rN   Úhttps)Ú	cache_dirÚosÚpathÚisabsrI   Úfeatures_enabledr1   Ú	Exceptionr   ÚjoinrK   rP   rF   ÚcertÚverifyÚclient_certrL   ÚproxyÚproxiesÚno_inputÚauthÚ	promptingÚkeyring_provider)r7   r;   rK   rL   rM   rS   rQ   Úsessionr/   r/   r0   rH   i   s<    

û	
þ
z"SessionCommandMixin._build_session)NNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   Úclassmethodr   r   r   ÚstrrF   r   rJ   ÚintÚboolrH   Ú__classcell__r/   r/   r8   r0   r2   G   s      ûúr2   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)rK   rL   rM   )ÚhasattrrI   Údisable_pip_version_checkr<   rH   ÚminrL   r   )r7   r;   rc   r/   r/   r0   Úhandle_pip_version_check§   s    
ø
z*IndexGroupCommand.handle_pip_version_check)rd   re   rf   rg   r   rr   r/   r/   r/   r0   rm   Ÿ   s   rm   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!   ro   rT   r'   Úplatformrs   r+   r,   r/   r/   r/   r0   Úwarn_if_run_as_rootÉ   s    
ÿrw   )Ú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)ry   Útr/   r/   r0   Úconfigure_tempdir_registryì   s    z0with_cleanup.<locals>.configure_tempdir_registry)r7   r;   Úargsr$   c                    sR   | j d k	st‚|jrˆ | j ƒ zˆ| ||ƒW S  tk
rL   ˆ | j ƒ ‚ Y nX d S r3   )Útempdir_registryrI   Úno_cleanr   )r7   r;   r~   ©r}   rx   r/   r0   Úwrapperð   s    

zwith_cleanup.<locals>.wrapper)r   ÚRequirementCommandr   r   r   r   rj   )rx   r‚   r/   r�   r0   Ú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 r3   )r4   r5   Úcmd_optsÚ
add_optionr
   r€   )r7   r~   r…   r8   r/   r0   r5     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ú2020-resolver)Údeprecated_features_enabled©r;   r/   r/   r0   Údetermine_resolver_variant	  s    
z-RequirementCommand.determine_resolver_variantr   )	Útemp_build_dirr;   Úbuild_trackerrc   Ú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.)Ú	build_dirÚsrc_dirr‘   Úbuild_isolationÚcheck_build_depsrŽ   rc   Úprogress_barr�   Úrequire_hashesr�   Ú
lazy_wheelr’   Úlegacy_resolver)rU   rI   rŒ   rW   r+   r,   r   r”   r•   r–   r—   r˜   )rB   r�   r;   rŽ   rc   r�   r�   r‘   r’   Útemp_build_dir_pathrš   Úresolver_variantr™   r/   r/   r0   Ú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Œ   Ú,pip._internal.resolution.resolvelib.resolverÚ	_internalÚ
resolutionÚ
resolvelibÚresolverÚResolverr©   Ú(pip._internal.resolution.legacy.resolverrˆ   )rB   rŸ   r�   r;   r    r�   r¡   r¢   r£   r¤   r¥   r¦   r¨   rœ   Úpipr/   r/   r0   Úmake_resolverH  sF    ý
õõz RequirementCommand.make_resolver)r~   r;   r�   rc   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)Ú
constraintr�   r;   rc   F)r§   Úuser_suppliedNÚconfig_settings)Ú
comes_fromr§   r¥   rµ   r¶   )rµ   r§   r¥   r¶   )r�   r;   rc   )r§   r¥   rµ   r¶   c                 s   s   | ]}|j V  qd S r3   )Úhas_hash_options)Ú.0Úreqr/   r/   r0   Ú	<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ª   r@   r   r¥   r?   Ú	editablesr   Úrequirementsr;   ÚgetÚanyr˜   r¼   Ú
find_linksr   ÚformatÚdictrY   )r7   r~   r;   r�   rc   rÁ   ÚfilenameÚ
parsed_reqÚ
req_to_addrº   Úoptsr/   r/   r0   Ú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_scopeÚget_formatted_locationsr+   Úinfo)r�   rÌ   Ú	locationsr/   r/   r0   Útrace_basic_info×  s    z#RequirementCommand.trace_basic_info)r;   rc   Ú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)Úallow_yankedÚformat_controlÚallow_all_prereleasesÚprefer_binaryr¢   )Úlink_collectorÚselection_prefsrÑ   )r   Úcreater   rÓ   ÚprerÕ   r   )r7   r;   rc   rÑ   r¢   rÖ   r×   r/   r/   r0   Ú_build_package_finderâ  s    ûýz(RequirementCommand._build_package_finder)Nr   )NFTFFrž   NN)NN)rd   re   rf   r   r5   Ústaticmethodr   ri   rŒ   rh   r   r   r   r   rk   r   rj   r   r�   r	   r   r   r³   r   r   rË   rÐ   r   rÚ   rl   r/   r/   r8   r0   rƒ     sr   	  ÷ö6        ôó<úT  ûúrƒ   )Irg   ÚloggingrT   r'   Ú	functoolsr   Úoptparser   Útypingr   r   r   r   r   Úpip._internal.cacher	   Zpip._internal.clir
   Úpip._internal.cli.base_commandr   Ú!pip._internal.cli.command_contextr   Úpip._internal.exceptionsr   r   Úpip._internal.index.collectorr   Ú"pip._internal.index.package_finderr   Ú$pip._internal.models.selection_prefsr   Ú"pip._internal.models.target_pythonr   Úpip._internal.network.sessionr   Ú,pip._internal.operations.build.build_trackerr   Ú pip._internal.operations.preparer   Úpip._internal.req.constructorsr   r   r   r   Zpip._internal.req.req_filer   Zpip._internal.req.req_installr   Úpip._internal.resolution.baser   Ú!pip._internal.self_outdated_checkr   Úpip._internal.utils.temp_dirr   r   r    Úpip._internal.utils.virtualenvr!   r)   r"   Ú	getLoggerrd   r+   r1   r2   rm   Ú	BUILD_ENVÚEPHEM_WHEEL_CACHEÚ	REQ_BUILDrz   rw   r„   rƒ   r/   r/   r/   r0   Ú<module>   sL   
X$ý