U
    „~$hu  ã                   @   s¶   d dl Z d dlmZ d dl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mZ d dlmZ d dlmZ e  e¡ZG dd„ deƒZdS )é    N)ÚValues)ÚAnyÚDictÚList)Údefault_environment)Ú
print_json)Ú__version__)Ú
cmdoptions)ÚCommand)ÚSUCCESS)ÚBaseDistributionÚget_environment)Ústdlib_pkgs)Úpath_to_urlc                   @   sT   e Zd ZdZdZdZddœdd„Zeee	 e
dœd	d
„Zeee	ef dœdd„ZdS )ÚInspectCommandzZ
    Inspect the content of a Python environment and produce a report in JSON format.
    Tz
      %prog [options]N)Úreturnc                 C   sN   | j jddddd� | j jdddddd	� | j  t ¡ ¡ | j d
| j ¡ d S )Nz--localÚ
store_trueFzSIf in a virtualenv that has global access, do not list globally-installed packages.)ÚactionÚdefaultÚhelpz--userÚuserz,Only output packages installed in user-site.)Údestr   r   r   r   )Úcmd_optsÚ
add_optionr	   Ú	list_pathÚparserÚinsert_option_group©Úself© r   úB/tmp/pip-unpacked-wheel-g27rp152/pip/_internal/commands/inspect.pyÚadd_options   s    û	ûzInspectCommand.add_options)ÚoptionsÚargsr   c                    sT   t  |¡ t|jƒj|j|jttƒd�}dt	‡ fdd„|D ƒt
ƒ dœ}t|d� tS )N)Ú
local_onlyÚ	user_onlyÚskipÚ1c                    s   g | ]}ˆ   |¡‘qS r   )Ú_dist_to_dict)Ú.0Údistr   r   r    Ú
<listcomp>:   s     z&InspectCommand.run.<locals>.<listcomp>)ÚversionÚpip_versionÚ	installedÚenvironment)Údata)r	   Úcheck_list_path_optionr   ÚpathZiter_installed_distributionsÚlocalr   Úsetr   r   r   r   r   )r   r"   r#   ÚdistsÚoutputr   r   r    Úrun0   s    

ýü
zInspectCommand.run)r*   r   c                 C   sv   |j |jdœ}|j}|d k	r*| ¡ |d< n$|j}|d k	rNt|ƒddidœ|d< |j}|jrb||d< |jrr|j|d< |S )N)ÚmetadataZmetadata_locationÚ
direct_urlÚeditableT)ÚurlZdir_infoÚ	installerÚ	requested)	Zmetadata_dictZinfo_locationr9   Zto_dictÚeditable_project_locationr   r<   Zinstalled_with_dist_infor=   )r   r*   Úresr9   r>   r<   r   r   r    r(   A   s&    þ ÿþ

zInspectCommand._dist_to_dict)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úignore_require_venvÚusager!   r   r   ÚstrÚintr7   r   r   r   r(   r   r   r   r    r      s   r   )ÚloggingÚoptparser   Útypingr   r   r   Úpip._vendor.packaging.markersr   Zpip._vendor.richr   Úpipr   Zpip._internal.clir	   Úpip._internal.cli.base_commandr
   Úpip._internal.cli.status_codesr   Zpip._internal.metadatar   r   Úpip._internal.utils.compatr   Úpip._internal.utils.urlsr   Ú	getLoggerr@   Úloggerr   r   r   r   r    Ú<module>   s   
