3
[                 @   s   d dl m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 d dlmZmZ ejeZG dd	 d	eZd
d ZdddZdS )    )absolute_importN)
FeedParser)pkg_resources)canonicalize_name)Command)ERRORSUCCESSc                   s8   e Zd ZdZdZdZdZdZ fddZdd	 Z	  Z
S )
ShowCommandzx
    Show information about one or more installed packages.

    The output is in RFC-compliant mail header format.
    showz$
      %prog [options] <package> ...z*Show information about installed packages.Tc                s>   t t| j|| | jjddddddd | jjd| j d S )	Nz-fz--filesfiles
store_trueFz7Show the full list of installed files for each package.)destactiondefaulthelpr   )superr	   __init__cmd_opts
add_optionparserinsert_option_group)selfargskw)	__class__ </tmp/pip-install-65viz3iy/pip/pip/_internal/commands/show.pyr      s    zShowCommand.__init__c             C   s8   |st jd tS |}t|}t||j|jds4tS tS )Nz.ERROR: Please provide a package name or names.)
list_filesverbose)loggerwarningr   search_packages_infoprint_resultsr   r   r   )r   optionsr   queryresultsr   r   r   run'   s    
zShowCommand.run)__name__
__module____qualname____doc__nameusagesummaryignore_require_venvr   r&   __classcell__r   r   )r   r   r	      s   r	   c             #   s  i xt jD ]}|t|j< qW dd | D }xfdd|D D ]Ή  j j jdd  j D d}d}d}t t jrވ j	drȈ j
d}dd |D } fd	d|D } fd
d|D } j	dr܈ jd}nP j	dr j
d} fdd|D } fdd|D } j	dr. jd} j	drL j
d}||d<  j	drx, j
dD ]}	|	j rd|	j |d< P qdW t }
|
j| |
j }xdD ]}|j|||< qW g }x4|j D ](}	|	jdr|j|	tdd  qW ||d< |rt||d< |V  qFW dS )z
    Gather details from installed distributions. Print distribution name,
    version, location, and installed files. Installed files requires a
    pip generated 'installed-files.txt' in the distributions '.egg-info'
    directory.
    c             S   s   g | ]}t |qS r   )r   ).0r+   r   r   r   
<listcomp>?   s    z(search_packages_info.<locals>.<listcomp>c                s   g | ]}| kr | qS r   r   )r0   pkg)	installedr   r   r1   A   s    c             S   s   g | ]
}|j qS r   )project_name)r0   depr   r   r   r1   F   s    )r+   versionlocationrequiresNRECORDc             S   s   g | ]}|j d d qS ),r   )split)r0   lr   r   r   r1   N   s    c                s   g | ]}t jj j|qS r   )ospathjoinr7   )r0   p)distr   r   r1   O   s    c                s   g | ]}t jj| jqS r   )r=   r>   relpathr7   )r0   r@   )rA   r   r   r1   P   s    METADATAzinstalled-files.txtc                s   g | ]}t jj j|qS r   )r=   r>   r?   egg_info)r0   r@   )rA   r   r   r1   X   s    c                s   g | ]}t jj| jqS r   )r=   r>   rB   r7   )r0   r@   )rA   r   r   r1   Y   s    zPKG-INFOzentry_points.txtentry_points	INSTALLER	installermetadata-versionr-   	home-pageauthorauthor-emaillicensezClassifier: classifiersr   )rH   r-   rI   rJ   rK   rL   )r   working_setr   r4   r6   r7   r8   
isinstanceDistInfoDistributionhas_metadataget_metadata_linesget_metadatastripr   feedcloseget
splitlines
startswithappendlensorted)r$   r@   query_namespackage	file_listmetadatalinespathsrE   linefeed_parserpkg_info_dictkeyrM   r   )rA   r3   r   r!   4   s^    







r!   Fc       
         s  d}xt | D ]\}}d}|dkr0tjd |jdd  fddtjD }tjd	  tjd
|jdd tjd|jdd tjd|jdd tjd|jdd tjd|jdd tjd|jdd tjd|jdd tjddj|jdg  tjddj| |rtjd|jdd tjd|jdd tjd  x"|jd!g D ]}tjd"| qZW tjd# x&|jd$g D ]}tjd"|j  qW |rtjd% x&|jd&g D ]}	tjd"|	j  qW d&|krtjd' qW |S )(zD
    Print the informations from installed distributions found.
    FTr   z---r+    c                s(   g | ] } d d |j  D kr|jqS )c             S   s   g | ]
}|j qS r   )r+   )r0   requiredr   r   r   r1      s    z,print_results.<locals>.<listcomp>.<listcomp>)r8   r4   )r0   r2   )r+   r   r   r1      s    z!print_results.<locals>.<listcomp>zName: %szVersion: %sr6   zSummary: %sr-   zHome-page: %sz	home-pagez
Author: %srJ   zAuthor-email: %szauthor-emailzLicense: %srL   zLocation: %sr7   zRequires: %sz, r8   zRequired-by: %szMetadata-Version: %szmetadata-versionzInstaller: %srG   zClassifiers:rM   z  %szEntry-points:rE   zFiles:r   z!Cannot locate installed-files.txt)	enumerater   inforW   r   rN   r?   rT   )
distributionsr   r   results_printedirA   required_by
classifierentryrc   r   )r+   r   r"   }   sD    



r"   )FF)
__future__r   loggingr=   email.parserr   pip._vendorr   pip._vendor.packaging.utilsr   Zpip._internal.cli.base_commandr   Zpip._internal.cli.status_codesr   r   	getLoggerr'   r   r	   r!   r"   r   r   r   r   <module>   s   
$I