a
    ij4                     @  sP  d dl mZ d dlZd dlZd dlmZ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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#m$Z$ erd dl%m&Z& d dl'm(Z( G dd deZ)ee) Z*e+e,Z-G dd deZ.ddddddZ/dddddd Z0dS )!    )annotationsN)	GeneratorSequence)Parser)Values)TYPE_CHECKINGcastcanonicalize_name)InvalidVersionVersion)
cmdoptions)IndexGroupCommand)SUCCESS)CommandError)BaseDistributionget_environment)SelectionPreferences)stdlib_pkgs)tabulatewrite_outputPackageFinder)
PipSessionc                   @  s"   e Zd ZU dZded< ded< dS )_DistWithLatestInfozGive the distribution object a couple of extra fields.

        These will be populated during ``get_outdated()``. This is dirty but
        makes the rest of the code much cleaner.
        r   latest_versionstrlatest_filetypeN)__name__
__module____qualname____doc____annotations__ r#   r#   Y/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/pip/_internal/commands/list.pyr      s   
r   c                      s   e Zd ZdZdZdZddddZddd	 fd
dZddddddZddddddZ	ddddddZ
ddddddZddddddZdddddd Zddddd!d"Zd#ddd$d%d&Z  ZS )'ListCommandzt
    List installed packages, including editables.

    Packages are listed in a case-insensitive sorted order.
    Tz
      %prog [options]None)returnc                 C  s4  | j jdddddd | j jddddd	d | j jd
ddddd | j jdddddd | j jdddddd | j t  | j jddddddd | j jddddd | j jdd d!d"d | j jd#dd!d$d%d& | j t  ttj| j}ttj| j}| j	d'| | j	d'| | j	d'| j  d S )(Nz-oz
--outdated
store_trueFzList outdated packages)actiondefaulthelpz-uz
--uptodatezList uptodate packagesz-ez
--editablezList editable projects.z-lz--localzSIf in a virtualenv that has global access, do not list globally-installed packages.z--useruserz,Only output packages installed in user-site.)destr)   r*   r+   z--formatstorelist_formatcolumns)r0   freezejsonzSelect the output format among: columns (default), freeze, or json. The 'freeze' format cannot be used with the --outdated option.)r)   r-   r*   choicesr+   z--not-requirednot_requiredz>List packages that are not dependencies of installed packages.)r)   r-   r+   z--exclude-editablestore_falseinclude_editablez%Exclude editable package from output.z--include-editablez#Include editable package in output.T)r)   r-   r+   r*   r   )
cmd_opts
add_optionr   	list_pathlist_excludemake_option_groupindex_groupparserZpackage_selection_groupinsert_option_group)self
index_optsZselection_optsr#   r#   r$   add_options5   s    
zListCommand.add_optionsr   )optionsr'   c                   s   |j s|jrt | d S N)outdateduptodatesuperhandle_pip_version_check)r?   rB   	__class__r#   r$   rG      s    z$ListCommand.handle_pip_version_checkr   r   )rB   sessionr'   c                 C  sB   ddl m} ddlm} |j||d}td|jd}|j||dS )zK
        Create a package finder appropriate to this list command.
        r   )LinkCollectorr   )rB   F)allow_yankedrelease_control)link_collectorselection_prefs)pip._internal.index.collectorrK   "pip._internal.index.package_finderr   creater   rM   )r?   rB   rJ   rK   r   rN   rO   r#   r#   r$   _build_package_finder   s    z!ListCommand._build_package_finderz	list[str]int)rB   argsr'   c                 C  s   t | |jr|jrtd|jr6|jdkr6tdt | tt}|j	rd|
dd |j	D  dd t|jj|j|j|j|j|dD }|jr| ||}|jr| ||}n|jr| ||}| || tS )	Nz5Options --outdated and --uptodate cannot be combined.r1   z?List format 'freeze' cannot be used with the --outdated option.c                 s  s   | ]}t |V  qd S rC   r	   ).0nr#   r#   r$   	<genexpr>       z"ListCommand.run.<locals>.<genexpr>c                 S  s   g | ]}t d |qS )r   )r   )rV   dr#   r#   r$   
<listcomp>   s   z#ListCommand.run.<locals>.<listcomp>)
local_only	user_onlyeditables_onlyinclude_editablesskip)r   Zcheck_release_control_exclusiverD   rE   r   r/   check_list_path_optionsetr   excludesupdater   pathiter_installed_distributionslocalr,   editabler6   r4   get_not_requiredget_outdatedget_uptodateoutput_package_listingr   )r?   rB   rU   r`   packagesr#   r#   r$   run   s8    


zListCommand.run_ProcessedDistsrm   rB   r'   c                 C  s   dd |  ||D S )Nc                 S  s   g | ]}|j |jkr|qS r#   r   versionrV   distr#   r#   r$   r[      s   z,ListCommand.get_outdated.<locals>.<listcomp>iter_packages_latest_infosr?   rm   rB   r#   r#   r$   rj      s    
zListCommand.get_outdatedc                 C  s   dd |  ||D S )Nc                 S  s   g | ]}|j |jkr|qS r#   rq   rs   r#   r#   r$   r[      s   z,ListCommand.get_uptodate.<locals>.<listcomp>ru   rw   r#   r#   r$   rk      s    
zListCommand.get_uptodatec                   s$   dd |D  t  fdd|D S )Nc                 S  s(   h | ] }|  pd D ]}t|jqqS )r#   )iter_dependenciesr
   name)rV   rt   depr#   r#   r$   	<setcomp>   s   z/ListCommand.get_not_required.<locals>.<setcomp>c                   s   h | ]}|j  vr|qS r#   canonical_name)rV   pkgZdep_keysr#   r$   r{      rY   )listrw   r#   r   r$   ri      s    	zListCommand.get_not_requiredz*Generator[_DistWithLatestInfo, None, None]c                 #  sp    R}| ddd fdd}t||D ]}|d ur:|V  q:W d    n1 sb0    Y  d S )Nr   z_DistWithLatestInfo | Nonert   r'   c                   st     | j}| jr(dd |D } j| jd}||}|d u rLd S |j}|jjr`d}nd}|| _|| _	| S )Nc                 S  s   g | ]}|j js|qS r#   )rr   is_prerelease)rV   	candidater#   r#   r$   r[      s   zOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)project_namewheelsdist)
find_all_candidatesr}   Zshould_exclude_prereleasemake_candidate_evaluatorsort_best_candidaterr   linkis_wheelr   r   )rt   Zall_candidatesZ	evaluatorbest_candidateremote_versiontypfinderrB   r?   r#   r$   latest_info   s$    
z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)_build_sessionrS   map)r?   rm   rB   rJ   r   rt   r#   r   r$   rv      s    z&ListCommand.iter_packages_latest_infosc              	   C  s   t |dd d}|jdkr:|r:t||\}}| || n|jdkr|D ]b}z|j d|j }W n$ ty   |j d|j }Y n0 |jdkrt	d	||j
 qHt	| qHn|jd
krt	t|| d S )Nc                 S  s   | j S rC   r|   )rt   r#   r#   r$   <lambda>  rY   z4ListCommand.output_package_listing.<locals>.<lambda>)keyr0   r1   z==z===   z%s (%s)r2   )sortedr/   format_for_columnsoutput_package_listing_columnsraw_namerr   r   raw_versionverboser   locationformat_for_json)r?   rm   rB   dataheaderrt   
req_stringr#   r#   r$   rl     s$    


z"ListCommand.output_package_listingzlist[list[str]])r   r   r'   c                 C  sb   t |dkr|d| t|\}}t |dkrL|dddd |D  |D ]}t| qPd S )Nr   r    c                 s  s   | ]}d | V  qdS )-Nr#   rV   xr#   r#   r$   rX   7  rY   z=ListCommand.output_package_listing_columns.<locals>.<genexpr>)leninsertr   joinr   )r?   r   r   Zpkg_stringssizesvalr#   r#   r$   r   ,  s    z*ListCommand.output_package_listing_columns)r   r   r    r!   ignore_require_venvusagerA   rG   rS   rn   rj   rk   ri   rv   rl   r   __classcell__r#   r#   rH   r$   r%   *   s   U+		%r%   ro   r   z!tuple[list[list[str]], list[str]])pkgsrB   r'   c                   sX  ddg}|j }|r |ddg ddddd	  fd
d| D }t|}|rX|d tdd | D }|rx|d |jdkr|d |jdkr|d g }t| D ]\}}	|	j|	jg}
|r|
t|	j	 |
|	j
 |r|
|| pd |r|
|	jp
d |jdkr,|
|	jp(d |jdkrD|
|	j ||
 q||fS )z_
    Convert the package data into something usable
    by output_package_listing_columns.
    Packager   ZLatestTyper   z
str | Noner   c                 S  s6   z|  d}W n ty"   Y d S 0 t |dS )NZWHEELBuild)	read_textFileNotFoundErrorr   parsestrget)rt   
wheel_filer#   r#   r$   wheel_build_tagJ  s
    z+format_for_columns.<locals>.wheel_build_tagc                   s   g | ]} |qS r#   r#   )rV   pr   r#   r$   r[   Q  rY   z&format_for_columns.<locals>.<listcomp>r   c                 s  s   | ]}|j V  qd S rC   )rh   r   r#   r#   r$   rX   V  rY   z%format_for_columns.<locals>.<genexpr>zEditable project locationr   ZLocationZ	Installer )rD   extendanyappendr   	enumerater   r   r   r   r   editable_project_locationr   	installer)r   rB   r   Zrunning_outdatedZ
build_tagsZhas_build_tagsZhas_editablesr   iZprojrowr#   r   r$   r   =  s@    





r   r   rp   c              	   C  s   g }| D ]}zt |j}W n ty2   |j}Y n0 |j|d}|jdkrb|jpRd|d< |j|d< |jrt |j	|d< |j
|d< |j}|r||d< || qt|S )	N)ry   rr   r   r   r   r   r   r   r   )r   rr   r   r   r   r   r   r   rD   r   r   r   r   r2   dumps)rm   rB   r   rt   rr   infor   r#   r#   r$   r   y  s(    


r   )1
__future__r   r2   loggingcollections.abcr   r   email.parserr   optparser   typingr   r   pip._vendor.packaging.utilsr
   Zpip._vendor.packaging.versionr   r   Zpip._internal.clir   Zpip._internal.cli.index_commandr   pip._internal.cli.status_codesr   pip._internal.exceptionsr   pip._internal.metadatar   r   $pip._internal.models.selection_prefsr   pip._internal.utils.compatr   pip._internal.utils.miscr   r   rQ   r   pip._internal.network.sessionr   r   ro   	getLoggerr   loggerr%   r   r   r#   r#   r#   r$   <module>   s6   

  <