o
    {ŸŽiiB  ã                   @   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 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%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 ddl7m8Z8 e 9e:¡Z;G dd„ deƒZ<G dd„ dee<ƒZ=e6j>e6j?e6j@gZAd%dd„ZBd e	de	fd!d"„ZCG d#d$„ d$e=ƒZDd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)ÚAnyÚListÚOptionalÚTuple)Ú
WheelCache)Ú
cmdoptions)ÚCommand)ÚCommandContextMixIn)ÚCommandErrorÚPreviousBuildDirError)ÚLinkCollector)ÚPackageFinder)ÚSelectionPreferences)ÚTargetPython)Ú
PipSession)ÚRequirementPreparer)Úinstall_req_from_editableÚinstall_req_from_lineÚ#install_req_from_parsed_requirementÚinstall_req_from_req_string)Úparse_requirements)ÚInstallRequirement)ÚRequirementTracker)ÚBaseResolver)Úpip_self_version_check)ÚTempDirectoryÚTempDirectoryTypeRegistryÚtempdir_kinds)Úrunning_under_virtualenvc                	       sz   e Zd ZdZd‡ fdd„Zededeee	  fdd„ƒZ
dedefd	d
„Z		ddedee dee defdd„Z‡  ZS )ÚSessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    ÚreturnNc                    s   t ƒ  ¡  d | _d S ©N)ÚsuperÚ__init__Ú_session)Úself©Ú	__class__© úgC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\pip/_internal/cli/req_command.pyr%   5   s   

zSessionCommandMixin.__init__Úoptionsc                 C   sL   g }t |ddƒst |ddƒ}|r| |¡ t |ddƒ}|r"| |¡ |p%d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*   r+   Ú_get_index_urls9   s   

z#SessionCommandMixin._get_index_urlsc                 C   s0   | j du r|  |  |¡¡| _ | j dusJ ‚| j S )zGet a default-managed session.N)r&   Úenter_contextÚ_build_session)r'   r,   r*   r*   r+   Úget_default_sessionG   s   
z'SessionCommandMixin.get_default_sessionÚretriesÚtimeoutc                 C   s´   |j rtj |j ¡sJ ‚t|j rtj |j d¡nd |d ur|n|j|j|  |¡d�}|j	r1|j	|_
|jr8|j|_	|js=|rG|d urC|n|j|_|jrR|j|jdœ|_|j |j_|S )NÚhttp)Úcacher;   Útrusted_hostsr4   )r=   Úhttps)Ú	cache_dirÚosÚpathÚisabsr   Újoinr;   r?   r7   ÚcertÚverifyÚclient_certr<   ÚproxyÚproxiesÚno_inputÚauthÚ	prompting)r'   r,   r;   r<   Úsessionr*   r*   r+   r9   Q   s&   ú

þz"SessionCommandMixin._build_session©r"   N©NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   Úclassmethodr   r   r   Ústrr7   r   r:   Úintr9   Ú__classcell__r*   r*   r(   r+   r!   /   s"    üþýüûr!   c                   @   s"   e Zd ZdZdeddf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.
    r,   r"   Nc                 C   sj   t |dƒsJ ‚|js|jrdS | j|dtd|jƒd�}|� t||ƒ W d  ƒ dS 1 s.w   Y  dS )z€
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r-   Nr   é   )r;   r<   )ÚhasattrÚdisable_pip_version_checkr-   r9   Úminr<   r   )r'   r,   rN   r*   r*   r+   Úhandle_pip_version_check‚   s   ÿ"ÿz*IndexGroupCommand.handle_pip_version_check)rQ   rR   rS   rT   r   r^   r*   r*   r*   r+   rY   z   s    rY   r"   c                   C   sb   t ƒ rdS ttdƒsdS tjdkstjdkrdS tjdks"tjdkr*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ÚcygwinÚdarwinÚlinuxr   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    r[   rB   ÚsysÚplatformr_   ÚloggerÚwarningr*   r*   r*   r+   Úwarn_if_run_as_root�   s   
ÿrh   Úfuncc              	      s>   dt ddfdd„‰ dtdtdtt dtt f‡ ‡fd	d
„}|S )zNDecorator for common logic related to managing temporary
    directories.
    Úregistryr"   Nc                 S   s   t D ]}|  |d¡ qd S )NF)ÚKEEPABLE_TEMPDIR_TYPESÚ
set_delete)rj   Útr*   r*   r+   Úconfigure_tempdir_registry¿   s   ÿz0with_cleanup.<locals>.configure_tempdir_registryr'   r,   Úargsc                    sH   | j d usJ ‚|jrˆ | j ƒ zˆ| ||ƒW S  ty#   ˆ | j ƒ ‚ w r#   )Útempdir_registryÚno_cleanr   )r'   r,   ro   ©rn   ri   r*   r+   ÚwrapperÃ   s   

ûzwith_cleanup.<locals>.wrapper)r   ÚRequirementCommandr   r   r   r   rW   )ri   rs   r*   rr   r+   Úwith_cleanupº   s   ÿÿÿþru   c                       sB  e Zd Zdededdf‡ fdd„Zededefdd	„ƒZe		d'd
e
dedededededee defdd„ƒZe									d(dedededee dedededededee deeedf  defdd„ƒZdee dedededee f
d d!„Zededdfd"d#„ƒZ		d)deded$ee dee def
d%d&„Z‡  ZS )*rt   ro   Úkwr"   Nc                    s&   t ƒ j|i |¤Ž | j t ¡ ¡ d S r#   )r$   r%   Úcmd_optsÚ
add_optionr	   rq   )r'   ro   rv   r(   r*   r+   r%   ×   s   zRequirementCommand.__init__r,   c                 C   s   d| j v rdS dS )zEDetermines which resolver should be used, based on the given options.zlegacy-resolverÚlegacyú2020-resolverN)Údeprecated_features_enabled©r,   r*   r*   r+   Údetermine_resolver_variantÜ   s   
z-RequirementCommand.determine_resolver_variantÚtemp_build_dirÚreq_trackerrN   ÚfinderÚuse_user_siteÚdownload_dirc                 C   s„   |j }|dus	J ‚|  |¡}	|	dkrd|jv }
|
rt d¡ nd}
d|jv r+t d¡ t||j||j|||j||j	||
d|jv d�S )	zQ
        Create a RequirementPreparer instance for the given parameters.
        Nrz   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.Fz;fast-deps has no effect when used with the legacy resolver.zin-tree-build)Ú	build_dirÚsrc_dirr‚   Úbuild_isolationr   rN   Úprogress_barr€   Úrequire_hashesr�   Ú
lazy_wheelÚin_tree_build)
rC   r}   Úfeatures_enabledrf   rg   r   r„   r…   r†   r‡   )r3   r~   r,   r   rN   r€   r�   r‚   Útemp_build_dir_pathÚresolver_variantrˆ   r*   r*   r+   Úmake_requirement_preparerä   s:   

ÿ€
ÿôz,RequirementCommand.make_requirement_preparerFTúto-satisfy-onlyÚpreparerÚwheel_cacheÚignore_installedÚignore_requires_pythonÚforce_reinstallÚupgrade_strategyÚ
use_pep517Úpy_version_info.c                 C   s†   t t|j|
d�}|  |¡}|dkr*d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•   rz   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.resolverry   )r3   r�   r€   r,   r�   r�   r‘   r’   r“   r”   r•   r–   r˜   rŒ   Úpipr*   r*   r+   Úmake_resolver  sF   ý
õõz RequirementCommand.make_resolverc              	   C   sJ  g }|j D ]}t|d|||d�D ]}t||jdd�}| |¡ qq|D ]}	t|	d|j|jdd�}| |¡ q#|jD ]}	t|	d|j|jd�}| |¡ q9|j	D ]}t||||d�D ]}t||j|jdd�}| |¡ qXqNt
d	d
„ |D ƒƒrwd|_|s£|js£|j	s£d| ji}
|jr™tdjdi t|
d |j¡d�¤Žƒ‚tdjdi |
¤Žƒ‚|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)Ú
constraintr€   r,   rN   F)r—   Úuser_suppliedN)r—   r•   r¥   )r¥   r—   r•   )r€   r,   rN   c                 s   s   � | ]}|j V  qd S r#   )Úhas_hash_options)Ú.0Úreqr*   r*   r+   Ú	<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}")r*   )Úconstraintsr   r   rš   r1   r   r•   Ú	editablesr   ÚrequirementsÚanyr‡   rª   Ú
find_linksr   ÚformatÚdictrE   )r'   ro   r,   r€   rN   r¯   ÚfilenameÚ
parsed_reqÚ
req_to_addr¨   Úoptsr*   r*   r+   Úget_requirementsQ  s‚   


ûýôû
ü

ÿü÷
ÿþÿÿÿÿz#RequirementCommand.get_requirementsc                 C   s$   | j }| ¡ }|rt |¡ dS dS )zE
        Trace basic information about the provided objects.
        N)Úsearch_scopeÚget_formatted_locationsrf   Úinfo)r€   r¹   Ú	locationsr*   r*   r+   Útrace_basic_info   s
   ÿz#RequirementCommand.trace_basic_infoÚtarget_pythonc                 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¾   N)r   Úcreater   rÀ   ÚprerÂ   r   )r'   r,   rN   r¾   r’   rÃ   rÄ   r*   r*   r+   Ú_build_package_finder«  s   ûýz(RequirementCommand._build_package_finderr#   )NFTFFrŽ   NNrP   )rQ   rR   rS   r   r%   Ústaticmethodr   rV   r}   rU   r   r   r   r   Úboolr   r   r�   r   r   rW   r   r£   r   r   r¸   r½   r   rÇ   rX   r*   r*   r(   r+   rt   Ö   s¦    	øþýüûúùø	÷1ôþýüûúùø	÷
öõôó:þýüû
úOûþýüûúrt   rO   )ErT   ÚloggingrB   rd   Ú	functoolsr   Úoptparser   Útypingr   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.preparer   Úpip._internal.req.constructorsr   r   r   r   Zpip._internal.req.req_filer   Zpip._internal.req.req_installr   Úpip._internal.req.req_trackerr   Úpip._internal.resolution.baser   Ú!pip._internal.self_outdated_checkr   Úpip._internal.utils.temp_dirr   r   r   Úpip._internal.utils.virtualenvr    Ú	getLoggerrQ   rf   r!   rY   Ú	BUILD_ENVÚEPHEM_WHEEL_CACHEÚ	REQ_BUILDrk   rh   ru   rt   r*   r*   r*   r+   Ú<module>   sH    
Ký
