o
    5e0                  	   @   s^  d dl Z d dlZd dlmZ d dlmZmZ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 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$m%Z% erd 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ede
eee.  ee. f fddZ/dddede.fddZ0dS )    N)Values)TYPE_CHECKING	GeneratorListOptionalSequenceTuplecastcanonicalize_name)
cmdoptions)IndexGroupCommand)SUCCESS)CommandError)LinkCollector)PackageFinder)BaseDistributionget_environment)SelectionPreferences)
PipSession)stdlib_pkgs)tabulatewrite_output)DistributionVersionc                   @   s"   e Zd ZU dZeed< e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.
        latest_versionlatest_filetypeN)__name__
__module____qualname____doc__r   __annotations__str r#   r#   N/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/commands/list.pyr      s   
 r   c                   @   s   e Zd ZdZdZdZd ddZded	ede	fd
dZ
dedee defddZdddeddfddZdddeddfddZdddeddfddZdddeded fddZdddeddfddZdeee  dee ddfddZdS )!ListCommandzt
    List installed packages, including editables.

    Packages are listed in a case-insensitive sorted order.
    Tz
      %prog [options]returnNc                 C   s*  | 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 | 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}| 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--prezYInclude pre-release and development versions. By default, pip only finds stable versions.z--formatstorelist_formatcolumns)r/   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 from output.T)r(   r,   r*   r)   r   )	cmd_opts
add_optionr   	list_pathlist_excludemake_option_groupindex_groupparserinsert_option_group)self
index_optsr#   r#   r$   add_options2   s   

zListCommand.add_optionsoptionssessionc                 C   s*   t j||d}td|jd}tj||dS )zK
        Create a package finder appropriate to this list command.
        )rA   F)allow_yankedallow_all_prereleases)link_collectorselection_prefs)r   creater   prer   )r>   rA   rB   rE   rF   r#   r#   r$   _build_package_finder   s   z!ListCommand._build_package_finderargsc                 C   s   |j r
|jr
td|j r|jdkrtdt| tt}|jr-|	dd |jD  dd t
|jj|j|j|j|j|dD }|jrL| ||}|j rV| ||}n	|jr_| ||}| || tS )	Nz5Options --outdated and --uptodate cannot be combined.r0   z?List format 'freeze' cannot be used with the --outdated option.c                 s   s    | ]}t |V  qd S Nr
   ).0nr#   r#   r$   	<genexpr>       z"ListCommand.run.<locals>.<genexpr>c                 S   s   g | ]}t d |qS )r   )r	   )rL   dr#   r#   r$   
<listcomp>   s    z#ListCommand.run.<locals>.<listcomp>)
local_only	user_onlyeditables_onlyinclude_editablesskip)outdateduptodater   r.   r   check_list_path_optionsetr   excludesupdater   pathiter_installed_distributionslocalr+   editabler5   r3   get_not_requiredget_outdatedget_uptodateoutput_package_listingr   )r>   rA   rJ   rV   packagesr#   r#   r$   run   s6   

zListCommand.runre   _ProcessedDistsc                 C      dd |  ||D S )Nc                 S   s   g | ]
}|j |jkr|qS r#   r   versionrL   distr#   r#   r$   rQ      
    z,ListCommand.get_outdated.<locals>.<listcomp>iter_packages_latest_infosr>   re   rA   r#   r#   r$   rb         
zListCommand.get_outdatedc                 C   rh   )Nc                 S   s   g | ]
}|j |jkr|qS r#   ri   rk   r#   r#   r$   rQ      rm   z,ListCommand.get_uptodate.<locals>.<listcomp>rn   rp   r#   r#   r$   rc      rq   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)rL   rl   depr#   r#   r$   	<setcomp>   s    
z/ListCommand.get_not_required.<locals>.<setcomp>c                    s   h | ]	}|j  vr|qS r#   canonical_name)rL   pkgdep_keysr#   r$   ru      s    )listrp   r#   ry   r$   ra      s   	zListCommand.get_not_required)r   NNc                 #   sx    |  ,}| | dddtd f fdd}t||D ]	}|d ur)|V  q W d    d S 1 s5w   Y  d S )Nrl   r   r&   c                    sl     | j}jsdd |D } j| jd}||}|d u r"d S |j}|jjr,d}nd}|| _|| _	| S )Nc                 S   s   g | ]}|j js|qS r#   )rj   is_prerelease)rL   	candidater#   r#   r$   rQ      s    zOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)project_namewheelsdist)
find_all_candidatesrw   rH   make_candidate_evaluatorsort_best_candidaterj   linkis_wheelr   r   )rl   all_candidates	evaluatorbest_candidateremote_versiontypfinderrA   r#   r$   latest_info   s$   
z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)_build_sessionrI   r   map)r>   re   rA   rB   r   rl   r#   r   r$   ro      s   "z&ListCommand.iter_packages_latest_infosc                 C   s   t |dd d}|jdkr|rt||\}}| || d S |jdkrB|D ]}|jdkr7td|j|j|j q%td|j|j q%d S |jd	krPtt	|| d S d S )
Nc                 S   s   | j S rK   rv   )rl   r#   r#   r$   <lambda>  s    z4ListCommand.output_package_listing.<locals>.<lambda>)keyr/   r0      z%s==%s (%s)z%s==%sr1   )
sortedr.   format_for_columnsoutput_package_listing_columnsverboser   raw_namerj   locationformat_for_json)r>   re   rA   dataheaderrl   r#   r#   r$   rd     s$   


z"ListCommand.output_package_listingr   r   c                 C   sb   t |dkr|d| t|\}}t |dkr&|dddd |D  |D ]}t| q(d S )Nr   r    c                 s   s    | ]}d | V  qdS )-Nr#   rL   xr#   r#   r$   rN   ,  rO   z=ListCommand.output_package_listing_columns.<locals>.<genexpr>)leninsertr   joinr   )r>   r   r   pkg_stringssizesvalr#   r#   r$   r   !  s   
z*ListCommand.output_package_listing_columns)r&   N)r   r   r   r    ignore_require_venvusager@   r   r   r   rI   r   r"   intrf   rb   rc   ra   r   ro   rd   r   r#   r#   r#   r$   r%   '   sn    
X
)
	
	

&

r%   pkgsrg   rA   r&   c                 C   s   ddg}|j }|r|ddg tdd | D }|r |d |jdkr*|d	 |jdkr4|d
 g }| D ]A}|jt|jg}|rR|t|j ||j	 |r\||j
pZd |jdkri||jpgd |jdkrt||j || q8||fS )z_
    Convert the package data into something usable
    by output_package_listing_columns.
    PackageVersionLatestTypec                 s   s    | ]}|j V  qd S rK   )r`   r   r#   r#   r$   rN   ?  s    z%format_for_columns.<locals>.<genexpr>zEditable project locationr   Location	Installer )rW   extendanyappendr   r   r"   rj   r   r   editable_project_locationr   	installer)r   rA   r   running_outdatedhas_editablesr   projrowr#   r#   r$   r   2  s2   






r   re   c                 C   s   g }| D ]9}|j t|jd}|jdkr |jpd|d< |j|d< |jr/t|j|d< |j|d< |j	}|r8||d< |
| qt|S )	N)rs   rj   r   r   r   r   r   r   r   )r   r"   rj   r   r   r   rW   r   r   r   r   r1   dumps)re   rA   r   rl   infor   r#   r#   r$   r   _  s    



r   )1r1   loggingoptparser   typingr   r   r   r   r   r   r	   pip._vendor.packaging.utilsr   pip._internal.clir   pip._internal.cli.req_commandr   pip._internal.cli.status_codesr   pip._internal.exceptionsr   pip._internal.index.collectorr   "pip._internal.index.package_finderr   pip._internal.metadatar   r   $pip._internal.models.selection_prefsr   pip._internal.network.sessionr   pip._internal.utils.compatr   pip._internal.utils.miscr   r   pip._internal.metadata.baser   r   rg   	getLoggerr   loggerr%   r"   r   r   r#   r#   r#   r$   <module>   s@    $

  
-