U
    ;»{jÚ/  ã                   @   s^  d 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" 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/m0Z0m1Z1 e 2e3¡Z4e1j5e1j6e1j7gZ8eedœdd„Z9G dd„ deƒZ:dS )zðContains the RequirementCommand base class.

This class is in a separate module so the commands that do not always
need PackageFinder capability don't unnecessarily import the
PackageFinder machinery and all its vendored dependencies, etc.
é    N)Úpartial)ÚValues)ÚAnyÚListÚOptionalÚTuple)Ú
WheelCache)Ú
cmdoptions)ÚIndexGroupCommand)ÚSessionCommandMixin)Ú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)ÚTempDirectoryÚTempDirectoryTypeRegistryÚtempdir_kinds)ÚfuncÚreturnc                    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_TYPESZ
set_delete)r!   Út© r$   ú>/tmp/pip-install-zsn1f9xv/pip/pip/_internal/cli/req_command.pyÚconfigure_tempdir_registry7   s    z0with_cleanup.<locals>.configure_tempdir_registry)ÚselfÚoptionsÚargsr    c                    sR   | j d k	st‚|jrˆ | j ƒ zˆ| ||ƒW S  tk
rL   ˆ | j ƒ ‚ Y nX d S ©N)Ztempdir_registryÚAssertionErrorÚno_cleanr   )r'   r(   r)   ©r&   r   r$   r%   Úwrapper;   s    

zwith_cleanup.<locals>.wrapper)r   ÚRequirementCommandr   r   r   r   Úint)r   r.   r$   r-   r%   Úwith_cleanup2   s      þr1   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 r*   )ÚsuperÚ__init__Úcmd_optsÚ
add_optionr	   r,   )r'   r)   r2   ©Ú	__class__r$   r%   r4   O   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ÚlegacyÚ
resolvelib)Zdeprecated_features_enabled©r(   r$   r$   r%   Údetermine_resolver_variantT   s    
z-RequirementCommand.determine_resolver_variantr   )	Útemp_build_dirr(   Úbuild_trackerÚsessionÚ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_dirrB   Úbuild_isolationÚcheck_build_depsr>   r?   Úprogress_barr@   Úrequire_hashesrA   Ú
lazy_wheelrC   Úlegacy_resolver)Úpathr+   r<   Zfeatures_enabledÚloggerÚwarningr   rE   rF   rG   rH   rI   )Úclsr=   r(   r>   r?   r@   rA   rB   rC   Ztemp_build_dir_pathrK   Úresolver_variantrJ   r$   r$   r%   Úmake_requirement_preparer\   s@    

ÿ
ÿòz,RequirementCommand.make_requirement_preparerFTúto-satisfy-only.)Úpreparerr@   r(   Úwheel_cacherA   Ú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.
        )ÚisolatedrY   r:   r   N)rS   r@   rT   Úmake_install_reqrA   Úignore_dependenciesrU   rV   rW   rX   rZ   )r   r   Úisolated_moder<   Z,pip._internal.resolution.resolvelib.resolverÚ	_internalÚ
resolutionr:   ÚresolverÚResolverr]   Z(pip._internal.resolution.legacy.resolverr9   )rO   rS   r@   r(   rT   rA   rU   rV   rW   rX   rY   rZ   r\   rP   Úpipr$   r$   r%   Úmake_resolver“   sF    ý
õõz RequirementCommand.make_resolver)r)   r(   r@   r?   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(   r?   F)r[   Úuser_suppliedNÚconfig_settings)Ú
comes_fromr[   rY   rf   rg   )rf   r[   rY   rg   )r@   r(   r?   )r[   rY   rf   rg   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^   Úappendr   rY   ÚgetattrÚ	editablesr   Úrequirementsr(   ÚgetÚanyrI   rm   Ú
find_linksr   ÚformatÚdictÚjoin)r'   r)   r(   r@   r?   rt   ÚfilenameZ
parsed_reqÚ
req_to_addrk   Úoptsr$   r$   r%   Ú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_locationsrM   Úinfo)r@   r   Ú	locationsr$   r$   r%   Útrace_basic_info$  s    z#RequirementCommand.trace_basic_info)r(   r?   Útarget_pythonrV   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_binaryrV   )Úlink_collectorÚselection_prefsr„   )r   Úcreater   r†   Úprerˆ   r   )r'   r(   r?   r„   rV   r‰   rŠ   r$   r$   r%   Ú_build_package_finder/  s    ûýz(RequirementCommand._build_package_finder)Nr   )NFTFFrR   NN)NN)Ú__name__Ú
__module__Ú__qualname__r   r4   Ústaticmethodr   Ústrr<   Úclassmethodr   r   r   r   Úboolr   r0   r   rQ   r   r   r   rd   r   r   r~   rƒ   r   r�   Ú__classcell__r$   r$   r7   r%   r/   N   sr   	  ÷ö6        ôó<úV  ûúr/   );Ú__doc__ÚloggingÚ	functoolsr   Úoptparser   Útypingr   r   r   r   Úpip._internal.cacher   Zpip._internal.clir	   Zpip._internal.cli.index_commandr
   r   Úpip._internal.exceptionsr   r   Zpip._internal.index.collectorr   Z"pip._internal.index.package_finderr   Ú$pip._internal.models.selection_prefsr   Ú"pip._internal.models.target_pythonr   Zpip._internal.network.sessionr   Z,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   Zpip._internal.resolution.baser   Úpip._internal.utils.temp_dirr   r   r   Ú	getLoggerrŽ   rM   Z	BUILD_ENVZEPHEM_WHEEL_CACHEZ	REQ_BUILDr"   r1   r/   r$   r$   r$   r%   Ú<module>   s8   
ý