o
    Ëý°j0  ã                	   @   sj  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r€d dl&m'Z' G dd„ deƒZ(e	e( Z)d dl*m+Z+ e ,e-¡Z.G dd„ deƒZ/dddede
eee0  ee0 f fdd„Z1dddede0fdd„Z2dS )é    N)ÚValues)ÚTYPE_CHECKINGÚIteratorÚ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 )Ú_DistWithLatestInfoz¾Give 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#   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/commands/list.pyr      s   
 r   )Úparsec                   @   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)r0   ÚfreezeÚjsonzBSelect the output format among: columns (default), freeze, or json)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_options4   s’   ûûûú
ûû
ú	üüûzListCommand.add_optionsÚoptionsÚsessionc                 C   s2   t j||d�}td|jd�}tj||d|jv d�S )zK
        Create a package finder appropriate to this list command.
        )rB   F)Úallow_yankedÚallow_all_prereleasesÚhtml5lib)Úlink_collectorÚselection_prefsÚuse_deprecated_html5lib)r   Úcreater   Úprer   Údeprecated_features_enabled)r?   rB   rC   rG   rH   r#   r#   r$   Ú_build_package_finder‰   s   þýz!ListCommand._build_package_finderÚargsc                 C   s¶   |j r
|jr
tdƒ‚t |¡ ttƒ}|jr!| dd„ |jD ƒ¡ dd„ t	|j
ƒj|j|j|j|j|d�D ƒ}|jr@|  ||¡}|j rJ|  ||¡}n	|jrS|  ||¡}|  ||¡ tS )Nz5Options --outdated and --uptodate cannot be combined.c                 s   s   � | ]}t |ƒV  qd S ©Nr
   )Ú.0Únr#   r#   r$   Ú	<genexpr>¥   s   € z"ListCommand.run.<locals>.<genexpr>c                 S   s   g | ]}t d |ƒ‘qS )r   )r	   )rP   Údr#   r#   r$   Ú
<listcomp>§   s    ÿÿz#ListCommand.run.<locals>.<listcomp>)Ú
local_onlyÚ	user_onlyÚeditables_onlyÚinclude_editablesÚskip)ÚoutdatedÚuptodater   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   rN   rY   Úpackagesr#   r#   r$   Úrun�   s.   

ûþzListCommand.runrh   Ú_ProcessedDistsc                 C   ó   dd„ |   ||¡D ƒS )Nc                 S   s,   g | ]}t t|jƒƒt t|jƒƒkr|‘qS r#   ©r%   r"   r   Úversion©rP   Údistr#   r#   r$   rT   Ä   ó
    þz,ListCommand.get_outdated.<locals>.<listcomp>©Úiter_packages_latest_infos©r?   rh   rB   r#   r#   r$   re   Á   ó   
þzListCommand.get_outdatedc                 C   rk   )Nc                 S   s,   g | ]}t t|jƒƒt t|jƒƒkr|‘qS r#   rl   rn   r#   r#   r$   rT   Í   rp   z,ListCommand.get_uptodate.<locals>.<listcomp>rq   rs   r#   r#   r$   rf   Ê   rt   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)rP   ro   Údepr#   r#   r$   Ú	<setcomp>Ö   s    
ýþÿz/ListCommand.get_not_required.<locals>.<setcomp>c                    s   h | ]	}|j ˆ vr|’qS r#   ©Úcanonical_name)rP   Úpkg©Údep_keysr#   r$   rx   ß   s    )Úlistrs   r#   r|   r$   rd   Ó   s   þ	zListCommand.get_not_requiredr   c                 #   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 )Nro   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#   )rm   Úis_prerelease)rP   Ú	candidater#   r#   r$   rT   í   s    ýÿzOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)Úproject_nameÚwheelÚsdist)
Úfind_all_candidatesrz   rK   Úmake_candidate_evaluatorÚsort_best_candidaterm   ÚlinkÚis_wheelr   r   )ro   Úall_candidatesÚ	evaluatorÚbest_candidateÚremote_versionÚtyp©ÚfinderrB   r#   r$   Úlatest_infoç   s$   þÿ
z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)Ú_build_sessionrM   r   Úmap)r?   rh   rB   rC   r�   ro   r#   rŽ   r$   rr   á   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 rO   ry   )ro   r#   r#   r$   Ú<lambda>  s    z4ListCommand.output_package_listing.<locals>.<lambda>)Úkeyr0   r1   é   z%s==%s (%s)z%s==%sr2   )
Úsortedr/   Úformat_for_columnsÚoutput_package_listing_columnsÚverboser   Úraw_namerm   ÚlocationÚformat_for_json)r?   rh   rB   ÚdataÚheaderro   r#   r#   r$   rg     s$   þ

ÿú
ÿz"ListCommand.output_package_listingr�   rž   c                 C   sb   t |ƒdkr| d|¡ t|ƒ\}}t |ƒdkr&| dd tdd„ |ƒ¡¡ |D ]}t|ƒ q(d S )Nr   r•   ú c                 S   s   d|  S )Nú-r#   )Úxr#   r#   r$   r“   '  s    z<ListCommand.output_package_listing_columns.<locals>.<lambda>)ÚlenÚinsertr   Újoinr’   r   )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ÚusagerA   r   r   r   rM   r   r"   Úintri   re   rf   rd   r   rr   rg   r˜   r#   r#   r#   r$   r&   )   sn    
Uÿÿ
þ$ÿÿ
þ	ÿÿ
þ	ÿÿ
þÿÿ
þ&ÿÿ
þ
ÿÿþr&   Úpkgsrj   rB   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 rO   )rc   )rP   r¡   r#   r#   r$   rR   :  s   € z%format_for_columns.<locals>.<genexpr>zEditable project locationr•   ÚLocationÚ	InstallerÚ )rZ   ÚextendÚanyÚappendr™   rš   r"   rm   r   r   Úeditable_project_locationr›   Ú	installer)r«   rB   rž   Úrunning_outdatedÚhas_editablesr�   ÚprojÚrowr#   r#   r$   r—   -  s2   






r—   rh   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)rv   rm   r•   r²   r›   r·   r   r   r¶   )rš   r"   rm   r™   r›   r·   rZ   r   r   r¶   rµ   r2   Údumps)rh   rB   r�   ro   Úinfor¶   r#   r#   r$   rœ   Z  s    þ



rœ   )3r2   Ú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   rj   Úpip._vendor.packaging.versionr%   Ú	getLoggerr   Úloggerr&   r"   r—   rœ   r#   r#   r#   r$   Ú<module>   sB    $

  ÿÿ
þ-