o
    h3                     @  sp  d Z ddlmZ ddl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 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/m0Z0 ddl1m2Z2m3Z3m4Z4 e5e6Z7e4j8e4j9e4j:gZ;d!ddZ<G dd  d eZ=dS )"zContains 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.
    )annotationsN)partial)Values)Any)#SubprocessBuildEnvironmentInstaller)
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_dependency_groups)parse_requirements)InstallRequirement)BaseResolver)TempDirectoryTempDirectoryTypeRegistrytempdir_kindsfuncr   returnc                   s   ddd d fdd}|S )zNDecorator for common logic related to managing temporary
    directories.
    registryr   r    Nonec                 S  s   t D ]}| |d qd S )NF)KEEPABLE_TEMPDIR_TYPES
set_delete)r!   t r&   P/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.pyconfigure_tempdir_registry;   s   z0with_cleanup.<locals>.configure_tempdir_registryselfRequirementCommandoptionsr   args	list[Any]
int | Nonec                   sH   | j d usJ |jr | j  z| ||W S  ty#    | j   w N)tempdir_registryno_cleanr   )r)   r+   r,   r(   r   r&   r'   wrapper?   s   

zwith_cleanup.<locals>.wrapperN)r!   r   r    r"   )r)   r*   r+   r   r,   r-   r    r.   r&   )r   r3   r&   r2   r'   with_cleanup6   s   
r4   c                      s   e Zd Zd; fddZed<ddZe		d=d>ddZe		 	!	 	 	"		d?d@d/d0ZdAd3d4Z	edBd5d6Z
		dCdDd9d:Z  ZS )Er*   r,   r   kwr    r"   c                   s6   t  j|i | | jt  | jt  d S r/   )super__init__cmd_opts
add_optionr   dependency_groupsr1   )r)   r,   r5   	__class__r&   r'   r7   S   s   zRequirementCommand.__init__r+   r   strc                 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
resolvelib)deprecated_features_enabledr+   r&   r&   r'   determine_resolver_variantY   s   
z-RequirementCommand.determine_resolver_variantNr   temp_build_dirr   build_trackerr   sessionr   finderr   use_user_sitebooldownload_dir
str | None	verbosityintr   c	                 C  s   |j }	|	dus	J d}
| |}|dkr!d|jv }|r td nd}
d}d|jv r/td tdi d|	d	|jd
|d|jdt|d|j	d|d|d|j
d|d|jd|d|d|d|
d|jS )zQ
        Create a RequirementPreparer instance for the given parameters.
        NFr?   z	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_dirrI   build_isolationbuild_isolation_installercheck_build_depsrD   rE   progress_barrF   require_hashesrG   
lazy_wheelrK   legacy_resolverresume_retriesr&   )pathrB   features_enabledloggerwarningr   rN   rO   r   rQ   rR   rS   rV   )clsrC   r+   rD   rE   rF   rG   rI   rK   temp_build_dir_pathrU   resolver_variantrT   r&   r&   r'   make_requirement_preparera   sd   


	
z,RequirementCommand.make_requirement_preparerFTto-satisfy-onlypreparerwheel_cacheWheelCache | Noneignore_installedignore_requires_pythonforce_reinstallupgrade_strategy
use_pep517bool | Nonepy_version_infotuple[int, ...] | Noner   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.
        )isolatedrg   r?   r   N)r`   rF   ra   make_install_reqrG   ignore_dependenciesrc   rd   re   rf   ri   )r   r   isolated_moderB   ,pip._internal.resolution.resolvelib.resolver	_internal
resolutionr?   resolverResolverrm   (pip._internal.resolution.legacy.resolverr>   )r[   r`   rF   r+   ra   rG   rc   rd   re   rf   rg   ri   rl   r]   pipr&   r&   r'   make_resolver   sF   
z RequirementCommand.make_resolver	list[str]list[InstallRequirement]c                 C  s  g }|j D ]}t|d|||dD ]}t||jdd}|| qq|D ]}	t|	d|j|jdt|ddd}|| q#|jrUt	|jD ]}	t
|	|j|jdd}|| qC|jD ]}	t|	d|j|jt|ddd	}|| qX|jD ]&}t||||d
D ]}t||j|jd|jr|jdndd}|| q|qrtdd |D rd|_|s|js|js|jsd| ji}
|jrtdjdi t|
d|jdtdjdi |
|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)
constraintrF   r+   rE   F)rk   user_suppliedNconfig_settings)
comes_fromrk   rg   rz   r{   )rk   rg   rz   )rz   rk   rg   r{   )rF   r+   rE   )rk   rg   rz   r{   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   rn   appendr   rg   getattrr:   r   r   	editablesr   requirementsr+   getanyrS   r   
find_linksr   formatdictjoin)r)   r,   r+   rF   rE   r   filename
parsed_req
req_to_addr   optsr&   r&   r'   get_requirements   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_locationsrY   info)rF   r   	locationsr&   r&   r'   trace_basic_info:  s
   z#RequirementCommand.trace_basic_infotarget_pythonTargetPython | Nonec                 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.
        rA   T)allow_yankedformat_controlallow_all_prereleasesprefer_binaryrd   )link_collectorselection_prefsr   )r   creater   r   prer   r   )r)   r+   rE   r   rd   r   r   r&   r&   r'   _build_package_finderE  s   z(RequirementCommand._build_package_finder)r,   r   r5   r   r    r"   )r+   r   r    r=   )Nr   )rC   r   r+   r   rD   r   rE   r   rF   r   rG   rH   rI   rJ   rK   rL   r    r   )NFTFFr_   NN)r`   r   rF   r   r+   r   ra   rb   rG   rH   rc   rH   rd   rH   re   rH   rf   r=   rg   rh   ri   rj   r    r   )
r,   rw   r+   r   rF   r   rE   r   r    rx   )rF   r   r    r"   )NN)
r+   r   rE   r   r   r   rd   rh   r    r   )__name__
__module____qualname__r7   staticmethodrB   classmethodr^   rv   r   r   r   __classcell__r&   r&   r;   r'   r*   R   s0    	8
:er*   )r   r   r    r   )>__doc__
__future__r   logging	functoolsr   optparser   typingr   pip._internal.build_envr   pip._internal.cacher   pip._internal.clir   pip._internal.cli.index_commandr	   r
   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   &pip._internal.req.req_dependency_groupr   pip._internal.req.req_filer   pip._internal.req.req_installr   pip._internal.resolution.baser   pip._internal.utils.temp_dirr   r   r   	getLoggerr   rY   	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILDr#   r4   r*   r&   r&   r&   r'   <module>   s@    

