a
    hbòf½/  ã                   @   sX  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)e *e+¡Z,G dd„ deƒZ-dee
eee.  ee. f dœdd„Z/dee.dœdd„Z0d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#   úX/home/httpd/docs/test/DocsMgr/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eee	dœd	d
„Z
eee edœdd„Zdeddœdd„Zdeddœdd„Zdeddœdd„Zdeed dœdd„Zdeddœdd„Zeee  ee ddœdd„ZdS )ÚListCommandzt
    List installed packages, including editables.

    Packages are listed in a case-insensitive sorted order.
    Tz
      %prog [options]N)Úreturnc                 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Ú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_options2   s’    ûûûú
ûû
ú	üüûzListCommand.add_options)ÚoptionsÚsessionr&   c                 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.
        )rA   F)Úallow_yankedÚallow_all_prereleasesÚhtml5lib)Úlink_collectorÚselection_prefsÚuse_deprecated_html5lib)r   Úcreater   Úprer   Údeprecated_features_enabled)r>   rA   rB   rF   rG   r#   r#   r$   Ú_build_package_finder‡   s    þýz!ListCommand._build_package_finder)rA   Úargsr&   c                 C   s¶   |j r|jrtdƒ‚t |¡ ttƒ}|jrB| 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.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	   )rO   Údr#   r#   r$   Ú
<listcomp>¥   s   ÿz#ListCommand.run.<locals>.<listcomp>)Ú
local_onlyÚ	user_onlyÚeditables_onlyÚinclude_editablesÚskip)ÚoutdatedZuptodater   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   rM   rY   Úpackagesr#   r#   r$   Úrun›   s.    

ûþzListCommand.runÚ_ProcessedDists©rg   rA   r&   c                 C   s   dd„ |   ||¡D ƒS )Nc                 S   s   g | ]}|j |jkr|‘qS r#   ©r   Úversion©rO   Údistr#   r#   r$   rT   Â   s   þz,ListCommand.get_outdated.<locals>.<listcomp>©Úiter_packages_latest_infos©r>   rg   rA   r#   r#   r$   rd   ¿   s    
þzListCommand.get_outdatedc                 C   s   dd„ |   ||¡D ƒS )Nc                 S   s   g | ]}|j |jkr|‘qS r#   rk   rm   r#   r#   r$   rT   Ë   s   þz,ListCommand.get_uptodate.<locals>.<listcomp>ro   rq   r#   r#   r$   re   È   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)rO   rn   Údepr#   r#   r$   Ú	<setcomp>Ô   s   þz/ListCommand.get_not_required.<locals>.<setcomp>c                    s   h | ]}|j ˆ vr|’qS r#   ©Úcanonical_name)rO   Úpkg©Zdep_keysr#   r$   ru   Ý   rR   )Úlistrq   r#   ry   r$   rc   Ñ   s    þ	zListCommand.get_not_requiredr   c                 #   sr   |   ˆ¡�T}|  ˆ|¡‰ dtd dœ‡ ‡fdd„}t||ƒD ]}|d ur<|V  q<W d   ƒ n1 sd0    Y  d S )Nr   )rn   r&   c                    sl   ˆ   | j¡}ˆjs dd„ |D ƒ}ˆ j| jd�}| |¡}|d u rDd S |j}|jjrXd}nd}|| _|| _	| S )Nc                 S   s   g | ]}|j js|‘qS r#   )rl   Úis_prerelease)rO   Ú	candidater#   r#   r$   rT   ë   s   þzOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)Úproject_nameÚwheelÚsdist)
Úfind_all_candidatesrw   rJ   Úmake_candidate_evaluatorÚsort_best_candidaterl   ÚlinkÚis_wheelr   r   )rn   Zall_candidatesZ	evaluatorÚbest_candidateÚremote_versionÚtyp©ÚfinderrA   r#   r$   Úlatest_infoå   s$    þÿ
z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)Ú_build_sessionrL   r   Úmap)r>   rg   rA   rB   rŠ   rn   r#   rˆ   r$   rp   ß   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 ]4}|jdkrltd|j|j|jƒ qHtd|j|jƒ qHn|jd	kr˜tt	||ƒƒ d S )
Nc                 S   s   | j S rN   rv   )rn   r#   r#   r$   Ú<lambda>
  rR   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_namerl   ÚlocationÚformat_for_json)r>   rg   rA   ÚdataÚheaderrn   r#   r#   r$   rf     s     þ

ÿ
z"ListCommand.output_package_listing)r—   r˜   r&   c                 C   sb   t |ƒdkr| d|¡ t|ƒ\}}t |ƒdkrL| dd tdd„ |ƒ¡¡ |D ]}t|ƒ qPd S )Nr   r�   ú c                 S   s   d|  S )Nú-r#   )Úxr#   r#   r$   r�   %  rR   z<ListCommand.output_package_listing_columns.<locals>.<lambda>)ÚlenÚinsertr   ÚjoinrŒ   r   )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Úusager@   r   r   r   rL   r   r"   Úintrh   rd   re   rc   r   rp   rf   r’   r#   r#   r#   r$   r%   '   s4   Vþ%þ
þ
þþ'þþr%   ri   )ÚpkgsrA   r&   c                 C   sü   ddg}|j }|r | ddg¡ tdd„ | D ƒƒ}|r@| d¡ |jdkrT| d	¡ |jdkrh| d
¡ g }| D ]‚}|jt|jƒg}|r¤| t|jƒ¡ | |j	¡ |r¸| |j
p´d¡ |jdkrÒ| |jpÎd¡ |jdkrè| |j¡ | |¡ qp||fS )z_
    Convert the package data into something usable
    by output_package_listing_columns.
    ÚPackageÚVersionZLatestÚTypec                 s   s   | ]}|j V  qd S rN   )rb   )rO   r›   r#   r#   r$   rQ   8  rR   z%format_for_columns.<locals>.<genexpr>zEditable project locationr�   ZLocationZ	InstallerÚ )rZ   ÚextendÚanyÚappendr“   r”   r"   rl   r   r   Úeditable_project_locationr•   Ú	installer)r¤   rA   r˜   Zrunning_outdatedZhas_editablesr—   ZprojÚrowr#   r#   r$   r‘   +  s2    






r‘   rj   c                 C   s†   g }| D ]r}|j t|jƒdœ}|jdkr@|jp0d|d< |j|d< |jr^t|jƒ|d< |j|d< |j	}|rp||d< | 
|¡ qt |¡S )	N)rs   rl   r�   r¨   r•   r­   r   r   r¬   )r”   r"   rl   r“   r•   r­   rZ   r   r   r¬   r«   r1   Údumps)rg   rA   r—   rn   Úinfor¬   r#   r#   r$   r–   X  s     þ


r–   )1r1   ÚloggingÚoptparser   Útypingr   r   r   r   r   r   r	   Úpip._vendor.packaging.utilsr   Z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   Zpip._internal.metadata.baser   r   ri   Ú	getLoggerr   Úloggerr%   r"   r‘   r–   r#   r#   r#   r$   Ú<module>   s6   $

  þ-