3
zYðii,  ã               @   sè   d dl mZ d dlZd dlZd dlZyd dlmZ W n  ek
rT   d dlmZ Y nX 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mZ ejeƒZG dd„ deƒZdd„ Zdd„ Zdd„ ZdS )é    )Úabsolute_importN)Úzip_longest)Úizip_longest)Úsix)ÚCommand)ÚCommandError)ÚPackageFinder)Úget_installed_distributionsÚdist_is_editable)ÚRemovedInPip10Warning)Úmake_option_groupÚindex_groupc                   s|   e Zd ZdZdZdZdZ‡ fdd„Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚListCommandzt
    List installed packages, including editables.

    Packages are listed in a case-insensitive sorted order.
    Úlistz
      %prog [options]zList installed packages.c                sâ   t t| ƒj||Ž | j}|jdddddd� |jddddd	d� |jd
ddddd� |jdddddd� | jjdddddd� |jddddd� |jdddd$dd� |jddd d!d"� tt| jƒ}| jjd#|ƒ | jjd#|ƒ 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ÚlegacyÚcolumnsÚfreezeÚjsonzJSelect the output format among: legacy (default), columns, freeze or json.)r   r   Úchoicesr   z--not-requiredÚnot_requiredz>List packages that are not dependencies of installed packages.)r   r   r   r   )r   r   r   r   )	Úsuperr   Ú__init__Úcmd_optsÚ
add_optionr   r   ÚparserÚinsert_option_group)ÚselfÚargsÚkwr    Ú
index_opts)Ú	__class__© ú0/tmp/pip-build-ue6tjl93/pip/pip/commands/list.pyr   #   s^    zListCommand.__init__c             C   s   t |j||j|j|j|d�S )zK
        Create a package finder appropriate to this list command.
        )Ú
find_linksÚ
index_urlsÚallow_all_prereleasesÚtrusted_hostsÚprocess_dependency_linksÚsession)r   r+   Úprer.   r/   )r$   Úoptionsr,   r0   r)   r)   r*   Ú_build_package_finderc   s    z!ListCommand._build_package_finderc             C   s¼   |j rtjdtƒ |jr$tjdtƒ |jr6tjdtƒ |jd krLtjdtƒ |jr`|jr`t	dƒ‚t
|j|j|jd�}|jrˆ| j||ƒ}n|jrš| j||ƒ}|jr¬| j||ƒ}| j||ƒ d S )Nz�--allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z“--allow-all-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z‘--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.zÇThe default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.z5Options --outdated and --uptodate cannot be combined.)Ú
local_onlyÚ	user_onlyÚeditables_only)Úallow_externalÚwarningsÚwarnr   Úallow_all_externalÚallow_unverifiedr   ÚoutdatedÚuptodater   r	   Úlocalr   ÚeditableÚget_outdatedÚget_uptodater   Úget_not_requiredÚoutput_package_listing)r$   r2   r%   Úpackagesr)   r)   r*   Úrunp   s<    

zListCommand.runc             C   s   dd„ | j ||ƒD ƒS )Nc             S   s   g | ]}|j |jkr|‘qS r)   )Úlatest_versionÚparsed_version)Ú.0Údistr)   r)   r*   ú
<listcomp>¨   s    z,ListCommand.get_outdated.<locals>.<listcomp>)Úiter_packages_latest_infos)r$   rD   r2   r)   r)   r*   r@   ¦   s    zListCommand.get_outdatedc             C   s   dd„ | j ||ƒD ƒS )Nc             S   s   g | ]}|j |jkr|‘qS r)   )rF   rG   )rH   rI   r)   r)   r*   rJ   ®   s    z,ListCommand.get_uptodate.<locals>.<listcomp>)rK   )r$   rD   r2   r)   r)   r*   rA   ¬   s    zListCommand.get_uptodatec                sB   t ƒ ‰ x$|D ]}ˆ jdd„ |jƒ D ƒƒ qW t ‡ fdd„|D ƒƒS )Nc             s   s   | ]}|j V  qd S )N)Úkey)rH   Úrequirementr)   r)   r*   ú	<genexpr>µ   s    z/ListCommand.get_not_required.<locals>.<genexpr>c             3   s   | ]}|j ˆ kr|V  qd S )N)rL   )rH   Úpkg)Údep_keysr)   r*   rN   ¶   s    )ÚsetÚupdateÚrequires)r$   rD   r2   rI   r)   )rP   r*   rB   ²   s    
zListCommand.get_not_requiredc             c   sø   |j g|j }|jr*tjddj|ƒƒ g }g }x&|D ]}|jdƒr4|j|jdƒƒ q4W | j	|ƒ�Ž}| j
|||ƒ}|j|ƒ xn|D ]f}d}|j|jƒ}	|js¨dd„ |	D ƒ}	|	s®q€t|	|jd�}
|
j}|
jjrÐd}nd	}||_||_|V  q€W W d Q R X d S )
NzIgnoring indexes: %sú,zdependency_links.txtÚunknownc             S   s   g | ]}|j js|‘qS r)   )ÚversionÚis_prerelease)rH   Ú	candidater)   r)   r*   rJ   Î   s    z:ListCommand.iter_packages_latest_infos.<locals>.<listcomp>)rL   ÚwheelÚsdist)Ú	index_urlÚextra_index_urlsÚno_indexÚloggerÚdebugÚjoinÚhas_metadataÚextendÚget_metadata_linesÚ_build_sessionr3   Úadd_dependency_linksÚfind_all_candidatesrL   r1   ÚmaxÚ_candidate_sort_keyrV   ÚlocationÚis_wheelrF   Úlatest_filetype)r$   rD   r2   r,   Údependency_linksrI   r0   ÚfinderÚtypÚall_candidatesÚbest_candidateÚremote_versionr)   r)   r*   rK   ¸   s8    




z&ListCommand.iter_packages_latest_infosc             C   s0   t |ƒrd|j|j|jf S d|j|jf S d S )Nz%s (%s, %s)z%s (%s))r
   Úproject_namerV   ri   )r$   rI   r)   r)   r*   Úoutput_legacyß   s    
zListCommand.output_legacyc             C   s   d| j |ƒ|j|jf S )Nz%s - Latest: %s [%s])rs   rF   rk   )r$   rI   r)   r)   r*   Úoutput_legacy_latesté   s    z ListCommand.output_legacy_latestc             C   s¼   t |dd„ d�}|jdkr:|r:t||ƒ\}}| j||ƒ n~|jdkrfxr|D ]}tjd|j|jƒ qJW nR|jdkr‚tjt||ƒƒ n6x4|D ],}|j	r¤tj| j
|ƒƒ qˆtj| j|ƒƒ qˆW d S )Nc             S   s
   | j jƒ S )N)rr   Úlower)rI   r)   r)   r*   Ú<lambda>ó   s    z4ListCommand.output_package_listing.<locals>.<lambda>)rL   r   r   z%s==%sr   )Úsortedr   Úformat_for_columnsÚoutput_package_listing_columnsr^   Úinforr   rV   Úformat_for_jsonr<   rt   rs   )r$   rD   r2   ÚdataÚheaderrI   r)   r)   r*   rC   ð   s    



z"ListCommand.output_package_listingc             C   sh   t |ƒdkr|jd|ƒ t|ƒ\}}t |ƒdkrL|jddjtdd„ |ƒƒƒ x|D ]}tj|ƒ qRW d S )Nr   é   ú c             S   s   d|  S )Nú-r)   )Úxr)   r)   r*   rv     s    z<ListCommand.output_package_listing_columns.<locals>.<lambda>)ÚlenÚinsertÚtabulater`   Úmapr^   rz   )r$   r|   r}   Úpkg_stringsÚsizesÚvalr)   r)   r*   ry     s    
z*ListCommand.output_package_listing_columns)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚusageÚsummaryr   r3   rE   r@   rA   rB   rK   rs   rt   rC   ry   Ú__classcell__r)   r)   )r(   r*   r      s   @6'
r   c             C   sˆ   t | ƒdkst‚dgtdd„ | D ƒƒ }x | D ]}dd„ t||ƒD ƒ}q.W g }x0| D ](}djdd„ t||ƒD ƒƒ}|j|ƒ qTW ||fS )Nr   c             s   s   | ]}t |ƒV  qd S )N)r‚   )rH   r�   r)   r)   r*   rN     s    ztabulate.<locals>.<genexpr>c             S   s"   g | ]\}}t |tt|ƒƒƒ‘qS r)   )rg   r‚   Ústr)rH   ÚsÚcr)   r)   r*   rJ     s    ztabulate.<locals>.<listcomp>r   c             S   s*   g | ]"\}}|d k	r"t |ƒj|ƒnd‘qS )NÚ )r‘   Úljust)rH   r’   r“   r)   r)   r*   rJ     s   )r‚   ÚAssertionErrorrg   r   r`   Úappend)Úvalsr‡   ÚrowÚresultÚdisplayr)   r)   r*   r„     s    


r„   c             C   sœ   |j }|rddddg}nddg}g }tdd„ | D ƒƒr@|jdƒ xR| D ]J}|j|jg}|rr|j|jƒ |j|jƒ t|ƒr†|j|jƒ |j|ƒ qFW ||fS )z_
    Convert the package data into something usable
    by output_package_listing_columns.
    ÚPackageÚVersionÚLatestÚTypec             s   s   | ]}t |ƒV  qd S )N)r
   )rH   r�   r)   r)   r*   rN   2  s    z%format_for_columns.<locals>.<genexpr>ÚLocation)	r<   Úanyr—   rr   rV   rF   rk   r
   ri   )Úpkgsr2   Úrunning_outdatedr}   r|   Úprojr™   r)   r)   r*   rx   %  s     

rx   c             C   sZ   g }xJ| D ]B}|j tj|jƒdœ}|jrBtj|jƒ|d< |j|d< |j|ƒ q
W tj	|ƒS )N)r�   rV   rF   rk   )
rr   r   Ú	text_typerV   r<   rF   rk   r—   r   Údumps)rD   r2   r|   rI   rz   r)   r)   r*   r{   F  s    

r{   ) Ú
__future__r   r   Úloggingr8   Ú	itertoolsr   ÚImportErrorr   Úpip._vendorr   Úpip.basecommandr   Úpip.exceptionsr   Ú	pip.indexr   Ú	pip.utilsr	   r
   Zpip.utils.deprecationr   Zpip.cmdoptionsr   r   Ú	getLoggerr‰   r^   r   r„   rx   r{   r)   r)   r)   r*   Ú<module>   s(   
 |!