3
ûâde«/  ã               @   sd  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% d dl&m'Z' e�rd dl(m)Z) G dd„ deƒZ*e	e* Z+ej,e-ƒZ.G dd„ deƒZ/dee
eee0  ee0 f dœdd„Z1dee0dœ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)Úmap_multithread)ÚDistributionVersionc               @   s   e Zd ZU dZee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.
        N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úlatest_versionÚstrÚlatest_filetype© r"   r"   ú:/tmp/pip-build-red6nood/pip/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 jtjƒ ƒ | 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 jtjƒ ƒ tjtj| jƒ}| jjd*|ƒ | j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Ú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   )r.   r/   r0   )	Úcmd_optsÚ
add_optionr   Z	list_pathZlist_excludeÚmake_option_groupÚindex_groupÚparserÚinsert_option_group)ÚselfÚ
index_optsr"   r"   r#   Úadd_options3   s~    zListCommand.add_options)ÚoptionsÚsessionr%   c             C   s*   t j||d�}td|jd�}tj||d�S )zK
        Create a package finder appropriate to this list command.
        )r>   F)Zallow_yankedÚallow_all_prereleases)Úlink_collectorÚselection_prefs)r   Úcreater   Úprer   )r;   r>   r?   rA   rB   r"   r"   r#   Ú_build_package_finderˆ   s    
z!ListCommand._build_package_finder)r>   Úargsr%   c             C   s¶   |j r|jrtdƒ‚tj|ƒ ttƒ}|jrB|jdd„ |jD ƒƒ dd„ t	|j
ƒj|j|j|j|j|d�D ƒ}|jr€| j||ƒ}|j r”| j||ƒ}n|jr¦| j||ƒ}| j||ƒ tS )Nz5Options --outdated and --uptodate cannot be combined.c             s   s   | ]}t |ƒV  qd S )N)r
   )Ú.0Únr"   r"   r#   ú	<genexpr>£   s    z"ListCommand.run.<locals>.<genexpr>c             S   s   g | ]}t d |ƒ‘qS )r   )r	   )rG   Údr"   r"   r#   ú
<listcomp>¦   s   z#ListCommand.run.<locals>.<listcomp>)Ú
local_onlyÚ	user_onlyÚeditables_onlyÚinclude_editablesÚskip)ÚoutdatedÚuptodater   r   Zcheck_list_path_optionÚsetr   ZexcludesÚupdater   ÚpathZiter_installed_distributionsÚlocalr*   Úeditabler4   r2   Úget_not_requiredÚget_outdatedÚget_uptodateÚoutput_package_listingr   )r;   r>   rF   rP   Úpackagesr"   r"   r#   Úrun›   s*    

zListCommand.runÚ_ProcessedDists)r\   r>   r%   c             C   s   dd„ | j ||ƒD ƒS )Nc             S   s   g | ]}|j |jkr|‘qS r"   )r   Úversion)rG   Údistr"   r"   r#   rK   Ã   s   z,ListCommand.get_outdated.<locals>.<listcomp>)Úiter_packages_latest_infos)r;   r\   r>   r"   r"   r#   rY   ¿   s    zListCommand.get_outdatedc             C   s   dd„ | j ||ƒD ƒS )Nc             S   s   g | ]}|j |jkr|‘qS r"   )r   r_   )rG   r`   r"   r"   r#   rK   Ì   s   z,ListCommand.get_uptodate.<locals>.<listcomp>)ra   )r;   r\   r>   r"   r"   r#   rZ   È   s    zListCommand.get_uptodatec                s$   dd„ |D ƒ‰ t ‡ fdd„|D ƒƒS )Nc             S   s(   h | ] }|j ƒ pf D ]}t|jƒ’qqS r"   )Ziter_dependenciesr
   Úname)rG   r`   Údepr"   r"   r#   ú	<setcomp>Ô   s   z/ListCommand.get_not_required.<locals>.<setcomp>c                s   h | ]}|j ˆ kr|’qS r"   )Úcanonical_name)rG   Úpkg)Údep_keysr"   r#   rd   Ý   s    )Úlist)r;   r\   r>   r"   )rg   r#   rX   Ñ   s    zListCommand.get_not_requiredr   c             #   sb   | j ˆƒ�N}| jˆ|ƒ‰ dtd dœ‡ ‡fdd„}x t||ƒD ]}|d k	r>|V  q>W W d Q R X d S )Nr   )r`   r%   c                sl   ˆ j | jƒ}ˆjs dd„ |D ƒ}ˆ j| jd�}|j|ƒ}|d krDd S |j}|jjrXd}nd}|| _|| _	| S )Nc             S   s   g | ]}|j js|‘qS r"   )r_   Úis_prerelease)rG   Ú	candidater"   r"   r#   rK   ì   s   zOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)Úproject_nameÚwheelÚsdist)
Úfind_all_candidatesre   rD   Zmake_candidate_evaluatorZsort_best_candidater_   ÚlinkÚis_wheelr   r!   )r`   Úall_candidatesZ	evaluatorÚbest_candidateÚremote_versionÚtyp)Úfinderr>   r"   r#   Úlatest_infoå   s     

z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)Ú_build_sessionrE   r   r   )r;   r\   r>   r?   rv   r`   r"   )ru   r>   r#   ra   ß   s    z&ListCommand.iter_packages_latest_infosc             C   s    t |dd„ d�}|jdkr:|r:t||ƒ\}}| j||ƒ nb|jdkr„xV|D ]4}|jdkrntd|j|j|jƒ qJtd|j|jƒ qJW n|jd	krœtt	||ƒƒ d S )
Nc             S   s   | j S )N)re   )r`   r"   r"   r#   Ú<lambda>
  s    z4ListCommand.output_package_listing.<locals>.<lambda>)Úkeyr.   r/   é   z%s==%s (%s)z%s==%sr0   )
Úsortedr-   Úformat_for_columnsÚoutput_package_listing_columnsÚverboser   Úraw_namer_   ÚlocationÚformat_for_json)r;   r\   r>   ÚdataÚheaderr`   r"   r"   r#   r[     s    



z"ListCommand.output_package_listing)r‚   rƒ   r%   c             C   sf   t |ƒdkr|jd|ƒ t|ƒ\}}t |ƒdkrL|jddjtdd„ |ƒƒƒ x|D ]}t|ƒ qRW d S )Nr   rz   ú c             S   s   d|  S )Nú-r"   )Úxr"   r"   r#   rx   %  s    z<ListCommand.output_package_listing_columns.<locals>.<lambda>)ÚlenÚinsertr   ÚjoinÚmapr   )r;   r‚   rƒ   Úpkg_stringsÚsizesÚvalr"   r"   r#   r}     s    
z*ListCommand.output_package_listing_columns)r   r   r   r   Zignore_require_venvÚusager=   r   r   r   rE   r   r    Úintr]   rY   rZ   rX   r   ra   r[   r}   r"   r"   r"   r#   r$   (   s&   V%%r$   r^   )Úpkgsr>   r%   c             C   s   ddg}|j }|r |jddgƒ tdd„ | D ƒƒ}|r@|jdƒ |jdkrT|jd	ƒ |jdkrh|jd
ƒ g }xŠ| D ]‚}|jt|jƒg}|r¦|jt|jƒƒ |j|j	ƒ |rº|j|j
p¶dƒ |jdkrÔ|j|jpÐdƒ |jdkrê|j|jƒ |j|ƒ qrW ||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 )N)rW   )rG   r†   r"   r"   r#   rI   8  s    z%format_for_columns.<locals>.<genexpr>zEditable project locationrz   ÚLocationZ	InstallerÚ )rQ   ÚextendÚanyÚappendr~   r   r    r_   r   r!   Úeditable_project_locationr€   Ú	installer)r�   r>   rƒ   Úrunning_outdatedZhas_editablesr‚   ÚprojÚrowr"   r"   r#   r|   +  s2    







r|   )r\   r>   r%   c             C   sŠ   g }xz| D ]r}|j t|jƒdœ}|jdkrB|jp2d|d< |j|d< |jr`t|jƒ|d< |j|d< |j	}|rr||d< |j
|ƒ q
W tj|ƒS )	N)rb   r_   rz   r–   r€   r›   r   r!   rš   )r   r    r_   r~   r€   r›   rQ   r   r!   rš   r™   r0   Údumps)r\   r>   r‚   r`   Úinforš   r"   r"   r#   r�   X  s    



r�   )3r0   ÚloggingÚoptparser   Útypingr   r   r   r   r   r   r	   Úpip._vendor.packaging.utilsr
   Zpip._internal.clir   Zpip._internal.cli.req_commandr   Zpip._internal.cli.status_codesr   Zpip._internal.exceptionsr   Zpip._internal.index.collectorr   Z"pip._internal.index.package_finderr   Zpip._internal.metadatar   r   Z$pip._internal.models.selection_prefsr   Zpip._internal.network.sessionr   Zpip._internal.utils.compatr   Zpip._internal.utils.miscr   r   Zpip._internal.utils.parallelr   Zpip._internal.metadata.baser   r   r^   Ú	getLoggerr   Úloggerr$   r    r|   r�   r"   r"   r"   r#   Ú<module>   s6   $

  "+