U
    +|jôA  ã                   @   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„ ZBd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                       s>   e Zd ZdZ‡ fdd„Zedd„ ƒZdd„ Zdd	d
„Z‡  Z	S )ÚSessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    c                    s   t ƒ  ¡  d | _d S ©N)ÚsuperÚ__init__Ú_session)Úself©Ú	__class__© úeC:\Users\snmko\Desktop\web_content\django_cbt\venv\Lib\site-packages\pip/_internal/cli/req_command.pyr$   5   s    
zSessionCommandMixin.__init__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)ÚclsÚoptionsÚ
index_urlsÚurlÚurlsr)   r)   r*   Ú_get_index_urls:   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)r%   Úenter_contextÚ_build_sessionÚAssertionError)r&   r2   r)   r)   r*   Úget_default_sessionI   s    
z'SessionCommandMixin.get_default_sessionNc                 C   s´   |j rtj |j ¡st‚t|j r0tj |j d¡nd |d k	r>|n|j|j|  	|¡d�}|j
rb|j
|_|jrp|j|_
|jsz|rŽ|d k	r†|n|j|_|jr¤|j|jdœ|_|j |j_|S )NÚhttp)ÚcacheÚretriesÚtrusted_hostsr3   )r;   Úhttps)Ú	cache_dirÚosÚpathÚisabsr9   r   Újoinr=   r>   r6   ÚcertÚverifyÚclient_certÚtimeoutÚproxyÚproxiesÚno_inputÚauthÚ	prompting)r&   r2   r=   rH   Úsessionr)   r)   r*   r8   T   s&    ú

þz"SessionCommandMixin._build_session)NN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   Úclassmethodr6   r:   r8   Ú__classcell__r)   r)   r'   r*   r!   /   s   
r!   c                   @   s   e Zd ZdZ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.
    c              	   C   sT   t |dƒst‚|js|jrdS | j|dtd|jƒ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   é   )r=   rH   )Úhasattrr9   Údisable_pip_version_checkr+   r8   ÚminrH   r   )r&   r2   rN   r)   r)   r*   Úhandle_pip_version_check�   s      
ÿz*IndexGroupCommand.handle_pip_version_checkN)rO   rP   rQ   rR   rZ   r)   r)   r)   r*   rU   y   s   rU   c                   C   sb   t ƒ r
dS ttdƒsdS tjdks,tjdkr0dS tjdksDtjdkrTt ¡ dkrTd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 root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv)r    rW   rA   ÚsysÚplatformr[   ÚloggerÚwarningr)   r)   r)   r*   Úwarn_if_run_as_root�   s    
ÿrd   c                    s   dd„ ‰ ‡ ‡fdd„}|S )zNDecorator for common logic related to managing temporary
    directories.
    c                 S   s   t D ]}|  |d¡ qd S )NF)ÚKEEPABLE_TEMPDIR_TYPESÚ
set_delete)ÚregistryÚtr)   r)   r*   Úconfigure_tempdir_registryÀ   s    z0with_cleanup.<locals>.configure_tempdir_registryc                    sR   | j d k	st‚|jrˆ | j ƒ zˆ| ||ƒW S  tk
rL   ˆ | j ƒ ‚ Y nX d S r"   )Útempdir_registryr9   Úno_cleanr   )r&   r2   Úargs©ri   Úfuncr)   r*   ÚwrapperÅ   s    

zwith_cleanup.<locals>.wrapperr)   )rn   ro   r)   rm   r*   Úwith_cleanupº   s    rp   c                	       sb   e Zd Z‡ fdd„Zedd„ ƒZeddd„ƒZeddd„ƒZdd„ Z	edd„ ƒZ
ddd„Z‡  ZS )ÚRequirementCommandc                    s"   t ƒ j||Ž | j t ¡ ¡ d S r"   )r#   r$   Úcmd_optsÚ
add_optionr	   rk   )r&   rl   Úkwr'   r)   r*   r$   Ø   s    zRequirementCommand.__init__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©r2   r)   r)   r*   Údetermine_resolver_variantÞ   s    
z-RequirementCommand.determine_resolver_variantNc                 C   s„   |j }|dk	st‚|  |¡}	|	dkr>d|jk}
|
rVt d¡ nd}
d|jkrVt d¡ t||j||j|||j	||j
||
d|jkd�S )	zQ
        Create a RequirementPreparer instance for the given parameters.
        Nrv   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_dirÚdownload_dirÚbuild_isolationÚreq_trackerrN   Úprogress_barÚfinderÚrequire_hashesÚuse_user_siteÚ
lazy_wheelÚin_tree_build)rB   r9   ry   Úfeatures_enabledrb   rc   r   r{   r}   r   r�   )r1   Útemp_build_dirr2   r~   rN   r€   r‚   r|   Útemp_build_dir_pathÚresolver_variantrƒ   r)   r)   r*   Úmake_requirement_preparerç   s8    

ÿ
ÿôz,RequirementCommand.make_requirement_preparerFTúto-satisfy-onlyc                 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.
        )ÚisolatedÚ
use_pep517rv   r   N)Úpreparerr€   Úwheel_cacheÚmake_install_reqr‚   Úignore_dependenciesÚignore_installedÚignore_requires_pythonÚforce_reinstallÚupgrade_strategyÚpy_version_info)r   r   Úisolated_modery   Ú,pip._internal.resolution.resolvelib.resolverÚ	_internalÚ
resolutionÚ
resolvelibÚresolverÚResolverr�   Ú(pip._internal.resolution.legacy.resolverru   )r1   r�   r€   r2   rŽ   r‚   r‘   r’   r“   r”   rŒ   r•   r�   rˆ   Úpipr)   r)   r*   Úmake_resolver  sF    ý
õõz RequirementCommand.make_resolverc                 C   sL  g }|j D ]6}t|d|||d�D ]}t||jdd�}| |¡ q q
|D ]$}	t|	d|j|jdd�}| |¡ qF|jD ]"}	t|	d|j|jd�}| |¡ qr|j	D ]8}t||||d�D ]"}t||j|jdd�}| |¡ q°qœt
d	d
„ |D ƒƒrîd|_|�sH|j�sH|j	�sHd| ji}
|j�r8tdjf t|
d |j¡d�Žƒ‚ntdjf |
Žƒ‚|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)Ú
constraintr€   r2   rN   F)r‹   Úuser_suppliedN)r‹   rŒ   r¡   )r¡   r‹   rŒ   )r€   r2   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}"))Úconstraintsr   r   r–   r/   r   rŒ   Ú	editablesr   ÚrequirementsÚanyr�   r¦   Ú
find_linksr   ÚformatÚdictrD   )r&   rl   r2   r€   rN   r«   ÚfilenameÚ
parsed_reqÚ
req_to_addr¤   Úoptsr)   r)   r*   Úget_requirementsV  s|    
û
ýû
ü
   ÿ
ü
þÿÿÿz#RequirementCommand.get_requirementsc                 C   s    | j }| ¡ }|rt |¡ dS )zE
        Trace basic information about the provided objects.
        N)Úsearch_scopeÚget_formatted_locationsrb   Úinfo)r€   rµ   Ú	locationsr)   r)   r*   Útrace_basic_info¦  s    z#RequirementCommand.trace_basic_infoc                 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.
        rx   T)Úallow_yankedÚformat_controlÚallow_all_prereleasesÚprefer_binaryr’   )Úlink_collectorÚselection_prefsÚtarget_python)r   Úcreater   r»   Úprer½   r   )r&   r2   rN   rÀ   r’   r¾   r¿   r)   r)   r*   Ú_build_package_finder²  s    ûýz(RequirementCommand._build_package_finder)N)NFTFFrŠ   NN)NN)rO   rP   rQ   r$   Ústaticmethodry   rS   r‰   rŸ   r´   r¹   rÃ   rT   r)   r)   r'   r*   rq   ×   s,   
	 ø2        ô;P
  ûrq   )ErR   ÚloggingrA   r`   Ú	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    Ú	getLoggerrO   rb   r!   rU   Ú	BUILD_ENVÚEPHEM_WHEEL_CACHEÚ	REQ_BUILDre   rd   rp   rq   r)   r)   r)   r*   Ú<module>   sF   
Jý