B
    =)H[µ.  ã               @   sÎ   d dl mZ d dlZd dlZd dl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 e¡ZG dd„ de
ƒZdd„ Zdd„ Zdd„ ZdS )é    )Úabsolute_importN)Úsix)Úzip_longest)ÚCommand)Úindex_groupÚmake_option_group)ÚCommandError)ÚPackageFinder)ÚRemovedInPip11Warning)Údist_is_editableÚget_installed_distributions)Úget_installerc                   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d� |jddddd � |jd!d"d#d$d � |jd%dd#d&d'd(� tt| jƒ}| j d)|¡ | 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Úcolumns)Úlegacyr   ÚfreezeÚjsonzKSelect the output format among: columns (default), freeze, json, or legacy.)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   )	Úsuperr   Ú__init__Úcmd_optsÚ
add_optionr   r   ÚparserÚinsert_option_group)ÚselfÚargsÚkwr"   Ú
index_opts)Ú	__class__© ú\C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\commands\list.pyr!   "   sv    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-   Úprer0   r1   )r&   Úoptionsr.   r2   r+   r+   r,   Ú_build_package_finderp   s    z!ListCommand._build_package_finderc             C   sŠ   |j dkrt dt¡ |jr*|jr*tdƒ‚t|j|j	|j
|jd�}|jrV|  ||¡}n|jrh|  ||¡}|jrz|  ||¡}|  ||¡ d S )Nr   zHThe legacy format has been deprecated and will be removed in the future.z5Options --outdated and --uptodate cannot be combined.)Ú
local_onlyÚ	user_onlyÚeditables_onlyÚinclude_editables)r   ÚwarningsÚwarnr
   ÚoutdatedÚuptodater   r   Úlocalr   Úeditabler   Úget_outdatedÚget_uptodater   Úget_not_requiredÚoutput_package_listing)r&   r4   r'   Úpackagesr+   r+   r,   Úrun}   s&    

zListCommand.runc             C   s   dd„ |   ||¡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   r4   r+   r+   r,   r@   š   s    zListCommand.get_outdatedc             C   s   dd„ |   ||¡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   r4   r+   r+   r,   rA       s    zListCommand.get_uptodatec                s>   t ƒ ‰ x$|D ]}ˆ  dd„ | ¡ D ƒ¡ qW ‡ 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                s   h | ]}|j ˆ kr|’qS r+   )rL   )rH   Úpkg)Údep_keysr+   r,   ú	<setcomp>ª   s    z/ListCommand.get_not_required.<locals>.<setcomp>)ÚsetÚupdateÚrequires)r&   rD   r4   rI   r+   )rP   r,   rB   ¦   s    
zListCommand.get_not_requiredc          	   c   sø   |j g|j }|jr*t dd |¡¡ g }g }x&|D ]}| d¡r4| | d¡¡ q4W |  	|¡�Ž}|  
|||¡}| |¡ xn|D ]f}d}| |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_sessionr5   Úadd_dependency_linksÚfind_all_candidatesrL   r3   ÚmaxÚ_candidate_sort_keyrW   ÚlocationÚis_wheelrF   Úlatest_filetype)r&   rD   r4   r.   Údependency_linksrI   r2   ÚfinderÚtypÚall_candidatesÚbest_candidateÚremote_versionr+   r+   r,   rK   ¬   s8    




z&ListCommand.iter_packages_latest_infosc             C   sT   |j dkr$d|j|j|jt|ƒf S t|ƒr@d|j|j|jf S d|j|jf S d S )Né   z%s (%s, %s, %s)z%s (%s, %s)z%s (%s))ÚverboseÚproject_namerW   rj   r   r   )r&   rI   r4   r+   r+   r,   Úoutput_legacyÓ   s    

zListCommand.output_legacyc             C   s   d|   ||¡|j|jf S )Nz%s - Latest: %s [%s])rv   rF   rl   )r&   rI   r4   r+   r+   r,   Úoutput_legacy_latestä   s    
z ListCommand.output_legacy_latestc             C   sì   t |dd„ d�}|jdkr:|r:t||ƒ\}}|  ||¡ n®|jdkrˆx¢|D ]8}|jdkrpt d|j|j|j	¡ qJt d|j|j¡ qJW n`|jd	kr¤t t
||ƒ¡ nD|jd
krèx8|D ]0}|jrÒt |  ||¡¡ q´t |  ||¡¡ q´W d S )Nc             S   s
   | j  ¡ S )N)ru   Úlower)rI   r+   r+   r,   Ú<lambda>î   s    z4ListCommand.output_package_listing.<locals>.<lambda>)rL   r   r   rs   z%s==%s (%s)z%s==%sr   r   )Úsortedr   Úformat_for_columnsÚoutput_package_listing_columnsrt   r_   Úinforu   rW   rj   Úformat_for_jsonr<   rw   rv   )r&   rD   r4   ÚdataÚheaderrI   r+   r+   r,   rC   ë   s&    






z"ListCommand.output_package_listingc             C   sh   t |ƒdkr| d|¡ t|ƒ\}}t |ƒdkrL| dd tdd„ |ƒ¡¡ x|D ]}t |¡ qRW d S )Nr   rs   ú c             S   s   d|  S )Nú-r+   )Úxr+   r+   r,   ry     s    z<ListCommand.output_package_listing_columns.<locals>.<lambda>)ÚlenÚinsertÚtabulatera   Úmapr_   r}   )r&   r   r€   Úpkg_stringsÚsizesÚvalr+   r+   r,   r|     s    
z*ListCommand.output_package_listing_columns)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚusageÚsummaryr!   r5   rE   r@   rA   rB   rK   rv   rw   rC   r|   Ú__classcell__r+   r+   )r*   r,   r      s   N'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 dd„ t||ƒD ƒ¡}| |¡ 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+   )rh   r„   Ústr)rH   ÚsÚcr+   r+   r,   rJ     s    ztabulate.<locals>.<listcomp>r�   c             S   s*   g | ]"\}}|d k	r"t |ƒ |¡nd‘qS )NÚ )r“   Úljust)rH   r”   r•   r+   r+   r,   rJ     s   )r„   ÚAssertionErrorrh   r   ra   Ú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 }|jdks@tdd„ | D ƒƒrJ| d¡ |jdkr^| d	¡ xt| D ]l}|j|jg}|r�| |j¡ | |j¡ |jdks¢t|ƒr®| |j	¡ |jdkrÆ| t
|ƒ¡ | |¡ qdW ||fS )
z_
    Convert the package data into something usable
    by output_package_listing_columns.
    ÚPackageÚVersionÚLatestÚTypers   c             s   s   | ]}t |ƒV  qd S )N)r   )rH   rƒ   r+   r+   r,   rN   1  s    z%format_for_columns.<locals>.<genexpr>ÚLocationÚ	Installer)r<   rt   Úanyr™   ru   rW   rF   rl   r   rj   r   )Úpkgsr4   Úrunning_outdatedr€   r   Úprojr›   r+   r+   r,   r{   $  s(    




r{   c             C   sz   g }xj| D ]b}|j t |j¡dœ}|jdkrB|j|d< t|ƒ|d< |jrbt |j¡|d< |j	|d< | 
|¡ q
W t |¡S )N)r�   rW   rs   rj   Ú	installerrF   rl   )ru   r   Ú	text_typerW   rt   rj   r   r<   rF   rl   r™   r   Údumps)rD   r4   r   rI   r}   r+   r+   r,   r~   I  s    



r~   ) Ú
__future__r   r   Úloggingr:   Úpip._vendorr   Úpip._vendor.six.movesr   Úpip._internal.basecommandr   Zpip._internal.cmdoptionsr   r   Úpip._internal.exceptionsr   Úpip._internal.indexr	   Úpip._internal.utils.deprecationr
   Úpip._internal.utils.miscr   r   Úpip._internal.utils.packagingr   Ú	getLoggerr‹   r_   r   r†   r{   r~   r+   r+   r+   r,   Ú<module>   s$   
 |%