B
    od70                 @   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	Generator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 )_DistWithLatestInfozGive 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"   M/var/www/html/venv/lib/python3.7/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   s*   t j||d}td|jd}tj||dS )zK
        Create a package finder appropriate to this list command.
        )r@   F)allow_yankedallow_all_prereleases)link_collectorselection_prefs)r   creater   prer   )r=   r@   rA   rD   rE   r"   r"   r#   _build_package_finder   s    
z!ListCommand._build_package_finder)r@   argsr%   c             C   s   |j r|jrtd|j r,|jdkr,tdt| tt}|jrZ|	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.r/   z@List format 'freeze' can not be used with the --outdated option.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	   )rJ   dr"   r"   r#   
<listcomp>   s   z#ListCommand.run.<locals>.<listcomp>)
local_only	user_onlyeditables_onlyinclude_editablesskip)outdatedZuptodater   r-   r   check_list_path_optionsetr   excludesupdater   pathiter_installed_distributionslocalr*   editabler4   r2   get_not_requiredget_outdatedget_uptodateoutput_package_listingr   )r=   r@   rI   rS   packagesr"   r"   r#   run   s0    

zListCommand.run_ProcessedDists)ra   r@   r%   c             C   s   dd |  ||D S )Nc             S   s   g | ]}|j |jkr|qS r"   )r   version)rJ   distr"   r"   r#   rN      s   z,ListCommand.get_outdated.<locals>.<listcomp>)iter_packages_latest_infos)r=   ra   r@   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"   )r   rd   )rJ   re   r"   r"   r#   rN      s   z,ListCommand.get_uptodate.<locals>.<listcomp>)rf   )r=   ra   r@   r"   r"   r#   r_      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)rJ   re   depr"   r"   r#   	<setcomp>   s   z/ListCommand.get_not_required.<locals>.<setcomp>c                s   h | ]}|j  kr|qS r"   )canonical_name)rJ   pkg)dep_keysr"   r#   rj      s    )list)r=   ra   r@   r"   )rm   r#   r]      s    zListCommand.get_not_required)r   NNc          	   #   sb   |  N}| | dtd d fdd}x t||D ]}|d k	r>|V  q>W W d Q R X d S )Nr   )re   r%   c                sl     | j}js dd |D } j| jd}||}|d krDd S |j}|jjrXd}nd}|| _|| _	| S )Nc             S   s   g | ]}|j js|qS r"   )rd   is_prerelease)rJ   	candidater"   r"   r#   rN      s   zOListCommand.iter_packages_latest_infos.<locals>.latest_info.<locals>.<listcomp>)project_namewheelsdist)
find_all_candidatesrk   rG   make_candidate_evaluatorsort_best_candidaterd   linkis_wheelr   r   )re   Zall_candidatesZ	evaluatorbest_candidateremote_versiontyp)finderr@   r"   r#   latest_info   s     

z;ListCommand.iter_packages_latest_infos.<locals>.latest_info)_build_sessionrH   r   map)r=   ra   r@   rA   r}   re   r"   )r|   r@   r#   rf      s    z&ListCommand.iter_packages_latest_infosc             C   s   t |dd d}|jdkr:|r:t||\}}| || nb|jdkrxV|D ]4}|jdkrntd|j|j|j qJtd|j|j qJW n|jd	krtt	|| d S )
Nc             S   s   | j S )N)rk   )re   r"   r"   r#   <lambda>      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_namerd   locationformat_for_json)r=   ra   r@   dataheaderre   r"   r"   r#   r`   	  s    



z"ListCommand.output_package_listing)r   r   r%   c             C   sf   t |dkr|d| t|\}}t |dkrL|ddtdd | x|D ]}t| qRW d S )Nr   r    c             S   s   d|  S )N-r"   )xr"   r"   r#   r   )  r   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   rH   r   r!   intrb   r^   r_   r]   r   rf   r`   r   r"   r"   r"   r#   r$   '   s&   V*%r$   rc   )pkgsr@   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 }x| D ]}|jt|jg}|r|t|j ||j	 |r||j
pd |jdkr||jpd |jdkr||j || qrW ||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 )N)r\   )rJ   r   r"   r"   r#   rL   <  s    z%format_for_columns.<locals>.<genexpr>zEditable project locationr   ZLocationZ	Installer )rT   extendanyappendr   r   r!   rd   r   r   editable_project_locationr   	installer)r   r@   r   Zrunning_outdatedZhas_editablesr   Zprojrowr"   r"   r#   r   /  s2    







r   )ra   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< |
| q
W t|S )	N)rh   rd   r   r   r   r   r   r   r   )r   r!   rd   r   r   r   rT   r   r   r   r   r0   dumps)ra   r@   r   re   infor   r"   r"   r#   r   \  s    



r   )1r0   loggingoptparser   typingr   r   r   r   r   r   r	   Z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   rc   	getLoggerr   loggerr$   r!   r   r   r"   r"   r"   r#   <module>   s4   $

  "+