o
    8jF5                     @  sJ  d dl mZ d dlZd dlZd dlZd dlmZ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rd 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Z0d#ddZ1d$d!d"Z2dS )%    )annotationsN)	GeneratorIterator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$   v/opt/pipey-apps/247c6e86-d9cc-49a2-98d3-9f311455f2db/.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ejd* fddZ	d+ddZ
d,ddZd-ddZd-ddZd-ddZd.d d!Zd/d"d#Zd0d'd(Z  ZS )1ListCommandzt
    List installed packages, including editables.

    Packages are listed in a case-insensitive sorted order.
    Tz
      %prog [options]returnNonec                 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)r1   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parserpackage_selection_groupinsert_option_group)self
index_optsselection_optsr$   r$   r%   add_options6   s   
zListCommand.add_optionsoptionsr   args	list[str]Iterator[None]c                 #  sR    |j s|jsd V  d S t || d V  W d    d S 1 s"w   Y  d S N)outdateduptodatesuperpip_version_check)rA   rE   rF   	__class__r$   r%   rM      s   "zListCommand.pip_version_checksessionr   r   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   )rE   F)allow_yankedrelease_control)link_collectorselection_prefs)pip._internal.index.collectorrQ   "pip._internal.index.package_finderr   creater   rS   )rA   rE   rP   rQ   r   rT   rU   r$   r$   r%   _build_package_finder   s   z!ListCommand._build_package_finderintc                 C  s   t | |jr|jrtd|jr|jdkrtdt | tt}|j	r2|
dd |j	D  dd t|jj|j|j|j|j|dD }|jrQ| ||}|jr[| ||}n	|jrd| ||}| || tS )	Nz5Options --outdated and --uptodate cannot be combined.r2   z?List format 'freeze' cannot be used with the --outdated option.c                 s  s    | ]}t |V  qd S rI   r
   ).0nr$   r$   r%   	<genexpr>       z"ListCommand.run.<locals>.<genexpr>c                 S  s   g | ]}t d |qS )r   )r	   )r[   dr$   r$   r%   
<listcomp>   s    z#ListCommand.run.<locals>.<listcomp>)
local_only	user_onlyeditables_onlyinclude_editablesskip)r   check_release_control_exclusiverJ   rK   r   r0   check_list_path_optionsetr   excludesupdater   pathiter_installed_distributionslocalr-   editabler7   r5   get_not_requiredget_outdatedget_uptodateoutput_package_listingr   )rA   rE   rF   re   packagesr$   r$   r%   run   s8   


zListCommand.runrs   _ProcessedDistsc                 C     dd |  ||D S )Nc                 S  s   g | ]
}|j |jkr|qS r$   r   versionr[   distr$   r$   r%   r`      
    z,ListCommand.get_outdated.<locals>.<listcomp>iter_packages_latest_infosrA   rs   rE   r$   r$   r%   rp         
zListCommand.get_outdatedc                 C  rv   )Nc                 S  s   g | ]
}|j |jkr|qS r$   rw   ry   r$   r$   r%   r`      r{   z,ListCommand.get_uptodate.<locals>.<listcomp>r|   r~   r$   r$   r%   rq      r   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)r[   rz   depr$   r$   r%   	<setcomp>   s    
z/ListCommand.get_not_required.<locals>.<setcomp>c                   s   h | ]	}|j  vr|qS r$   canonical_name)r[   pkgdep_keysr$   r%   r      s    )listr~   r$   r   r%   ro      s   	zListCommand.get_not_required*Generator[_DistWithLatestInfo, None, None]c                 #  sn     '}| d fdd}t||D ]	}|d ur$|V  qW d    d S 1 s0w   Y  d S )Nrz   r   r'   _DistWithLatestInfo | Nonec                   st     | j}| jrdd |D } j| jd}||}|d u r&d S |j}|jjr0d}nd}|| _|| _	| S )Nc                 S  s   g | ]}|j js|qS r$   )rx   is_prerelease)r[   	candidater$   r$   r%   r`      s    zOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)project_namewheelsdist)
find_all_candidatesr   should_exclude_prereleasemake_candidate_evaluatorsort_best_candidaterx   linkis_wheelr   r   )rz   all_candidates	evaluatorbest_candidateremote_versiontypfinderrE   rA   r$   r%   latest_info   s$   
z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)rz   r   r'   r   )_build_sessionrY   map)rA   rs   rE   rP   r   rz   r$   r   r%   r}      s   "z&ListCommand.iter_packages_latest_infosc              	   C  s   t |dd d}|jdkr|rt||\}}| || d S |jdkrY|D ]1}z|j d|j }W n tyD   |j d|j }Y nw |jdkrRt	d	||j
 q%t	| q%d S |jd
krgt	t|| d S d S )Nc                 S  s   | j S rI   r   )rz   r$   r$   r%   <lambda>  s    z4ListCommand.output_package_listing.<locals>.<lambda>)keyr1   r2   z==z===   z%s (%s)r3   )sortedr0   format_for_columnsoutput_package_listing_columnsraw_namerx   r   raw_versionverboser   locationformat_for_json)rA   rs   rE   dataheaderrz   
req_stringr$   r$   r%   rr     s*   



	z"ListCommand.output_package_listingr   list[list[str]]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$   r[   xr$   r$   r%   r]   <  r^   z=ListCommand.output_package_listing_columns.<locals>.<genexpr>)leninsertr   joinr   )rA   r   r   pkg_stringssizesvalr$   r$   r%   r   1  s   
z*ListCommand.output_package_listing_columns)r'   r(   )rE   r   rF   rG   r'   rH   )rE   r   rP   r   r'   r   )rE   r   rF   rG   r'   rZ   )rs   ru   rE   r   r'   ru   )rs   ru   rE   r   r'   r   )rs   ru   rE   r   r'   r(   )r   r   r   rG   r'   r(   )r   r    r!   r"   ignore_require_venvusagerD   
contextlibcontextmanagerrM   rY   rt   rp   rq   ro   r}   rr   r   __classcell__r$   r$   rN   r%   r&   +   s    
U


+
	
	

%r&   pkgsru   rE   r   r'   !tuple[list[list[str]], list[str]]c                   sH  ddg}|j }|r|ddg dd	d
  fdd| D }t|}|r)|d tdd | D }|r9|d |jdkrC|d |jdkrM|d g }t| D ]L\}}	|	j|	jg}
|rm|
t|	j	 |
|	j
 |rx|
|| pvd |r|
|	jpd |jdkr|
|	jpd |jdkr|
|	j ||
 qS||fS )z_
    Convert the package data into something usable
    by output_package_listing_columns.
    Packager   LatestTyperz   r   r'   
str | Nonec                 S  s6   z|  d}W n
 ty   Y d S w t |dS )NWHEELBuild)	read_textFileNotFoundErrorr   parsestrget)rz   
wheel_filer$   r$   r%   wheel_build_tagO  s   z+format_for_columns.<locals>.wheel_build_tagc                   s   g | ]} |qS r$   r$   )r[   pr   r$   r%   r`   V  s    z&format_for_columns.<locals>.<listcomp>r   c                 s  s    | ]}|j V  qd S rI   )rn   r   r$   r$   r%   r]   [  s    z%format_for_columns.<locals>.<genexpr>zEditable project locationr   Location	Installer N)rz   r   r'   r   )rJ   extendanyappendr   	enumerater   r   r   r   r   editable_project_locationr   	installer)r   rE   r   running_outdated
build_tagshas_build_tagshas_editablesr   iprojrowr$   r   r%   r   B  s@   








r   rs   r   c              	   C  s   g }| D ]J}zt |j}W n ty   |j}Y nw |j|d}|jdkr1|jp)d|d< |j|d< |jr@t |j	|d< |j
|d< |j}|rI||d< || qt|S )	N)r   rx   r   r   r   r   r   r   r   )r   rx   r   r   r   r   r   r   rJ   r   r   r   r   r3   dumps)rs   rE   r   rz   rx   infor   r$   r$   r%   r   ~  s*   




r   )r   ru   rE   r   r'   r   )rs   ru   rE   r   r'   r   )3
__future__r   r   r3   loggingcollections.abcr   r   r   email.parserr   optparser   typingr   r	   pip._vendor.packaging.utilsr   pip._vendor.packaging.versionr   r   pip._internal.clir   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   rW   r   pip._internal.network.sessionr   r   ru   	getLoggerr   loggerr&   r   r   r$   r$   r$   r%   <module>   s:    

  
<