B
    He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   st   t jdk rtdydd l} W n tk
r<   td d S X ydd l}W n tk
rf   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.   q/var/www/downstreamdata.science/rtclock/rtclock-venv/lib/python3.7/site-packages/pip/_internal/cli/req_command.py_create_truststore_ssl_context2   s    

r0   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().
    N)r#   c                s   t    d | _d S )N)super__init___session)self)	__class__r.   r/   r3   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)clsr7   
index_urlsurlurlsr.   r.   r/   _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)r4   enter_context_build_sessionAssertionError)r5   r7   r.   r.   r/   get_default_session_   s    
z'SessionCommandMixin.get_default_sessionF)r7   retriestimeoutfallback_to_certifir#   c             C   s   |j }|rtj|std|jkrPy
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)cacherG   trusted_hostsr?   ssl_context)rJ   https)	cache_dirospathisabsrE   features_enabledr0   	Exceptionr   joinrG   rL   rB   certverifyclient_certrH   proxyproxiesno_inputauth	promptingZkeyring_provider)r5   r7   rG   rH   rI   rO   rM   sessionr.   r.   r/   rD   i   s8    



z"SessionCommandMixin._build_session)NNF)__name__
__module____qualname____doc__r3   classmethodr   r   r   strrB   r   rF   intboolrD   __classcell__r.   r.   )r6   r/   r1   G   s     r1   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.
    N)r7   r#   c          	   C   sV   t |dst|js|jrdS | j|dtd|jdd}| t|| W dQ R X dS )z
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r8   Nr      T)rG   rH   rI   )hasattrrE   disable_pip_version_checkr8   rD   minrH   r   )r5   r7   r^   r.   r.   r/   handle_pip_version_check   s    
z*IndexGroupCommand.handle_pip_version_check)r_   r`   ra   rb   r   rm   r.   r.   r.   r/   rh      s   rh   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 )zOutput 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   zRunning 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!   rj   rP   r&   platformrn   r*   r+   r.   r.   r.   r/   warn_if_run_as_root   s    
rr   )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   xt D ]}| |d qW d S )NF)KEEPABLE_TEMPDIR_TYPES
set_delete)rt   tr.   r.   r/   configure_tempdir_registry   s    
z0with_cleanup.<locals>.configure_tempdir_registry)r5   r7   argsr#   c                sP   | j d k	st|jr | j  y| ||S  tk
rJ    | j   Y nX d S )N)tempdir_registryrE   no_cleanr   )r5   r7   ry   )rx   rs   r.   r/   wrapper   s    

zwith_cleanup.<locals>.wrapper)r   RequirementCommandr   r   r   r   re   )rs   r|   r.   )rx   rs   r/   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)ry   kwr#   c                s"   t  j|| | jt  d S )N)r2   r3   cmd_opts
add_optionr
   r{   )r5   ry   r   )r6   r.   r/   r3     s    zRequirementCommand.__init__)r7   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legacyz2020-resolver)deprecated_features_enabled)r7   r.   r.   r/   determine_resolver_variant	  s    
z-RequirementCommand.determine_resolver_variantr   )	temp_build_dirr7   build_trackerr^   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.
        NFz2020-resolverz	fast-depszpip 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   r^   progress_barr   require_hashesr   
lazy_wheelr   legacy_resolver)rQ   rE   r   rS   r*   r+   r   r   r   r   r   r   )r>   r   r7   r   r^   r   r   r   r   temp_build_dir_pathr   resolver_variantr   r.   r.   r/   make_requirement_preparer  s:    


z,RequirementCommand.make_requirement_preparerFTto-satisfy-only.)preparerr   r7   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   z2020-resolverr   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   )r>   r   r   r7   r   r   r   r   r   r   r   r   r   r   pipr.   r.   r/   make_resolverH  s@    
z RequirementCommand.make_resolver)ry   r7   r   r^   r#   c             C   s  g }xD|j D ]:}x4t|d|||dD ]}t||jdd}|| q$W qW x6|D ].}	t|	d|j|jdt|ddd}|| qPW x6|jD ],}	t	|	d|j|jt|ddd}|| qW xZ|j
D ]P}xJt||||d	D ]6}t||j|jd|jr|jdndd
}|| qW qW tdd |D r0d|_|s|js|j
sd| ji}
|jrztdjf t|
d|jdntdjf |
|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)
constraintr   r7   r^   F)r   user_suppliedNconfig_settings)
comes_fromr   r   r   r   )r   r   r   r   )r   r7   r^   )r   r   r   r   c             s   s   | ]}|j V  qd S )N)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   r;   	editablesr   requirementsr7   getanyr   r   
find_linksr   formatdictrU   )r5   ry   r7   r   r^   r   filename
parsed_req
req_to_addr   optsr.   r.   r/   get_requirements  sj    


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.   r/   trace_basic_info  s    z#RequirementCommand.trace_basic_info)r7   r^   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.
        )r7   T)allow_yankedformat_controlallow_all_prereleasesprefer_binaryr   )link_collectorselection_prefsr   )r   creater   r   prer   r   )r5   r7   r^   r   r   r   r   r.   r.   r/   _build_package_finder  s    z(RequirementCommand._build_package_finder)Nr   )NFTFFr   NN)NN)r_   r`   ra   r   r3   staticmethodr   rd   r   rc   r   r   r   r   rf   r   re   r   r   r	   r   r   r   r   r   r   r   r   r   rg   r.   r.   )r6   r/   r}     s6   	 ,       ,/N r}   )Irb   loggingrP   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"   	getLoggerr_   r*   r0   r1   rh   	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILDru   rr   r~   r}   r.   r.   r.   r/   <module>   sJ   
X$