3
gB                 @   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l3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl9m:Z: ej;e<Z=G dd deZ>G dd dee>Z?e8j@e8jAe8jBgZCdddd ZDe	e	d!d"d#ZEG d$d% d%e?ZFd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)
deprecated)TempDirectoryTempDirectoryTypeRegistrytempdir_kinds)running_under_virtualenvc                   sp   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dddZ  ZS )SessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    N)returnc                s   t  j  d | _d S )N)super__init___session)self)	__class__ [/var/www/tester-filtro-web/env/lib/python3.6/site-packages/pip/_internal/cli/req_command.pyr%   6   s    
zSessionCommandMixin.__init__)optionsr#   c             C   sL   g }t |dds*t |dd}|r*|j| t |dd}|rD|j| |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)   r*   _get_index_urls:   s    

z#SessionCommandMixin._get_index_urlsc             C   s0   | j dkr*| j| j|| _ | j dk	s*t| j S )zGet a default-managed session.N)r&   enter_context_build_sessionAssertionError)r'   r+   r)   r)   r*   get_default_sessionH   s    
z'SessionCommandMixin.get_default_session)r+   retriestimeoutr#   c             C   s   |j  stjj|j stt|j r2tjj|j dnd |d k	r@|n|j|j| j	|d}|j
rd|j
|_|jrr|j|_
|js||r|d k	r|n|j|_|jr|j|jd|_|j |j_|S )Nhttp)cacher;   trusted_hostsr3   )r=   https)	cache_dirospathisabsr9   r   joinr;   r?   r6   certverifyclient_certr<   proxyproxiesno_inputauthZ	prompting)r'   r+   r;   r<   sessionr)   r)   r*   r8   R   s"    
z"SessionCommandMixin._build_session)NN)__name__
__module____qualname____doc__r%   classmethodr   r   r   strr6   r   r:   intr8   __classcell__r)   r)   )r(   r*   r"   0   s    r"   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)r+   r#   c          
   C   sT   t |dst|js|jrdS | j|dtd|j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.
        r,   Nr      )r;   r<   )hasattrr9   disable_pip_version_checkr,   r8   minr<   r   )r'   r+   rM   r)   r)   r*   handle_pip_version_check   s    z*IndexGroupCommand.handle_pip_version_check)rN   rO   rP   rQ   r   r[   r)   r)   r)   r*   rV   {   s   rV   )r#   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j dkr@dS tj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!   rX   rB   sysplatformr\   loggerwarningr)   r)   r)   r*   warn_if_run_as_root   s    
rc   )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 ]}| j|d qW d S )NF)KEEPABLE_TEMPDIR_TYPES
set_delete)re   tr)   r)   r*   configure_tempdir_registry   s    
z0with_cleanup.<locals>.configure_tempdir_registry)r'   r+   argsr#   c                sP   | j d k	st|jr | j  y| ||S  tk
rJ    | j   Y nX d S )N)tempdir_registryr9   no_cleanr   )r'   r+   rj   )ri   rd   r)   r*   wrapper   s    

zwith_cleanup.<locals>.wrapper)r   RequirementCommandr   r   r   r   rT   )rd   rm   r)   )ri   rd   r*   with_cleanup   s    
ro   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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 )rn   N)rj   kwr#   c                s"   t  j|| | jjtj  d S )N)r$   r%   cmd_opts
add_optionr	   rl   )r'   rj   rp   )r(   r)   r*   r%      s    zRequirementCommand.__init__)r+   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)r+   r)   r)   r*   determine_resolver_variant   s    
z-RequirementCommand.determine_resolver_variant)temp_build_dirr+   req_trackerrM   finderuse_user_sitedownload_dirr#   c             C   s   |j }|dk	st| j|}	|	dkr>d|jk}
|
rVtjd nd}
d|jkrVtjd d|jk}d|jkrxtd	d
dd d|jkrtdddd t||j	||j
|||j||j||
|dS )zQ
        Create a RequirementPreparer instance for the given parameters.
        Nz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.Fz;fast-deps has no effect when used with the legacy resolver.zout-of-tree-buildzin-tree-buildz#In-tree builds are now the default.z.to remove the --use-feature=in-tree-build flagz22.1)reasonreplacementgone_inz"Out-of-tree builds are deprecated.)Z	build_dirsrc_dirrz   build_isolationrw   rM   progress_barrx   require_hashesry   
lazy_wheelin_tree_build)rC   r9   ru   features_enabledra   rb   rt   r   r   r~   r   r   r   )r2   rv   r+   rw   rM   rx   ry   rz   Ztemp_build_dir_pathresolver_variantr   r   r)   r)   r*   make_requirement_preparer   sH    





z,RequirementCommand.make_requirement_preparerFTto-satisfy-only.)preparerrx   r+   wheel_cachery   ignore_installedignore_requires_pythonforce_reinstallupgrade_strategy
use_pep517py_version_infor#   c             C   s   t t|j|
d}| j|}|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   rx   r   make_install_reqry   ignore_dependenciesr   r   r   r   r   )r   r   isolated_moderu   Z,pip._internal.resolution.resolvelib.resolver	_internal
resolutionZ
resolvelibresolverZResolverr   Z(pip._internal.resolution.legacy.resolverrs   )r2   r   rx   r+   r   ry   r   r   r   r   r   r   r   r   pipr)   r)   r*   make_resolver&  s@    
z RequirementCommand.make_resolver)rj   r+   rx   rM   r#   c             C   sf  g }xD|j D ]:}x4t|d|||dD ]}t||jdd}|j| q$W qW x,|D ]$}	t|	d|j|jdd}|j| qPW x,|jD ]"}	t|	d|j|jd}|j| qW xF|j	D ]<}x6t||||dD ]"}t||j|jdd}|j| qW qW t
d	d
 |D rd|_|p|jp|j	sbd| ji}
|jrRtdjf t|
dj|jdntdjf |
|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)Z
constraintrx   r+   rM   F)r   user_suppliedN)r   r   r   )r   r   r   )rx   r+   rM   c             s   s   | ]}|j V  qd S )N)Z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   r0   r   r   	editablesr   requirementsanyr   r   
find_linksr   formatdictrE   )r'   rj   r+   rx   rM   r   filenameZ
parsed_reqZ
req_to_addr   optsr)   r)   r*   get_requirementsa  sb    



z#RequirementCommand.get_requirements)rx   r#   c             C   s    | j }|j }|rtj| dS )zE
        Trace basic information about the provided objects.
        N)search_scopeZget_formatted_locationsra   info)rx   r   	locationsr)   r)   r*   trace_basic_info  s    z#RequirementCommand.trace_basic_info)r+   rM   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_controlZallow_all_prereleasesprefer_binaryr   )link_collectorselection_prefsr   )r   creater   r   prer   r   )r'   r+   rM   r   r   r   r   r)   r)   r*   _build_package_finder  s    z(RequirementCommand._build_package_finder)N)NFTFFr   NN)NN)rN   rO   rP   r   r%   staticmethodr   rS   ru   rR   r   r   r   r   boolr   r   r   r   r   rT   r   r   r   r   r   r   r   r   rU   r)   r)   )r(   r*   rn      s4   	6       ,/I rn   )GrQ   loggingrB   r_   	functoolsr   optparser   typingr   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   Z pip._internal.operations.preparer   Zpip._internal.req.constructorsr   r   r   r   Zpip._internal.req.req_filer   pip._internal.req.req_installr   pip._internal.req.req_trackerr   Zpip._internal.resolution.baser   Z!pip._internal.self_outdated_checkr   pip._internal.utils.deprecationr   pip._internal.utils.temp_dirr   r   r    pip._internal.utils.virtualenvr!   	getLoggerrN   ra   r"   rV   	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILDrf   rc   ro   rn   r)   r)   r)   r*   <module>   sF   
K