o
    {ŸŽi   ã                   @   s  d dl Z 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
 d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ e e¡ZG d	d
„ d
eƒZG dd„ deƒZde
edf de
edf defdd„Zdee dee fdd„Zdee dededefdd„Z dS )é    N)ÚValues)ÚIteratorÚListÚ
NamedTupleÚOptionalÚTuple©Úcanonicalize_name)ÚCommand)ÚERRORÚSUCCESS)ÚBaseDistributionÚget_default_environment)Úwrite_outputc                   @   s<   e Zd ZdZdZdZddd„Zded	ee	 de
fd
d„ZdS )ÚShowCommandzx
    Show information about one or more installed packages.

    The output is in RFC-compliant mail header format.
    z$
      %prog [options] <package> ...TÚreturnNc                 C   s,   | j jddddddd� | j d| j ¡ d S )	Nz-fz--filesÚfilesÚ
store_trueFz7Show the full list of installed files for each package.)ÚdestÚactionÚdefaultÚhelpr   )Úcmd_optsÚ
add_optionÚparserÚinsert_option_group)Úself© r   úeC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\pip/_internal/commands/show.pyÚadd_options   s   ûzShowCommand.add_optionsÚoptionsÚargsc                 C   s8   |s	t  d¡ tS |}t|ƒ}t||j|jd�st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   r    r!   ÚqueryÚresultsr   r   r   Úrun&   s   

ÿzShowCommand.run)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚusageÚignore_require_venvr   r   r   ÚstrÚintr*   r   r   r   r   r      s    

r   c                   @   sž   e Zd ZU eed< eed< eed< ee ed< ee ed< eed< eed< ee ed< eed	< eed
< eed< eed< eed< ee ed< eee  ed< dS )Ú_PackageInfoÚnameÚversionÚlocationÚrequiresÚrequired_byÚ	installerÚmetadata_versionÚclassifiersÚsummaryÚhomepageÚauthorÚauthor_emailÚlicenseÚentry_pointsr   N)r+   r,   r-   r1   Ú__annotations__r   r   r   r   r   r   r3   3   s    
 r3   Úentry.Úinfor   c                 C   sj   | r)| d dkr)|r|d dkr|d7 }n|dd… }| dd… } | r)| d dkst tjg |¢| ¢R Ž ƒS )aì  Convert a legacy installed-files.txt path into modern RECORD path.

    The legacy format stores paths relative to the info directory, while the
    modern format stores paths relative to the package root, e.g. the
    site-packages directory.

    :param entry: Path parts of the installed-files.txt entry.
    :param info: Path parts of the egg-info directory relative to package root.
    :returns: The converted entry.

    For best compatibility with symlinks, this does not use ``abspath()`` or
    ``Path.resolve()``, but tries to work with path parts:

    1. While ``entry`` starts with ``..``, remove the equal amounts of parts
       from ``info``; if ``info`` is empty, start appending ``..`` instead.
    2. Join the two directly.
    r   ú..éÿÿÿÿ)rE   Né   ©r1   ÚpathlibÚPath)rC   rD   r   r   r   Ú_covert_legacy_entryE   s   
ûrK   r(   c                 #   s´  � t ƒ }dd„ | ¡ D ƒ‰ dd„ | D ƒ}t‡ fdd„t| |ƒD ƒƒ}|r-t dd |¡¡ dtd	tt	 f‡ fd
d„}dtd	t
tt	  fdd„}dtd	t
tt	  fdd„}|D ]�}zˆ | }W n	 tyg   Y qVw z| d¡}	|	jdd�}
W n ty€   g }
Y nw ||ƒpˆ||ƒ}|du r�d}nt|ƒ}|j}t|jt	|jƒ|jp¢ddd„ | ¡ D ƒ||ƒ|j|jp³d| dg ¡| dd¡| dd¡| dd¡| dd¡| dd¡|
|d�V  qVd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   i | ]}|j |“qS r   )Úcanonical_name©Ú.0Údistr   r   r   Ú
<dictcomp>i   s    ÿÿz(search_packages_info.<locals>.<dictcomp>c                 S   s   g | ]}t |ƒ‘qS r   r   )rN   r4   r   r   r   Ú
<listcomp>m   s    z(search_packages_info.<locals>.<listcomp>c                    s   g | ]
\}}|ˆ vr|‘qS r   r   )rN   r4   Úpkg©Ú	installedr   r   rQ   o   s    zPackage(s) not found: %sú, Úcurrent_distr   c                    s   ‡ fdd„ˆ  ¡ D ƒS )Nc                    s2   g | ]}ˆ j d d„ | ¡ D ƒv r|jd pd‘qS )c                 S   s   h | ]}t |jƒ’qS r   )r	   r4   )rN   Údr   r   r   Ú	<setcomp>x   s    
ÿzSsearch_packages_info.<locals>._get_requiring_packages.<locals>.<listcomp>.<setcomp>ÚNameÚUNKNOWN)rL   Úiter_dependenciesÚmetadatarM   ©rV   r   r   rQ   u   s    
ÿýÿzIsearch_packages_info.<locals>._get_requiring_packages.<locals>.<listcomp>)Úvaluesr]   rS   r]   r   Ú_get_requiring_packagest   s   
þz5search_packages_info.<locals>._get_requiring_packagesrO   c                 S   s<   z|   d¡}W n
 ty   Y d S w dd„ t | ¡ ¡D ƒS )NÚRECORDc                 s   s"   � | ]}t t |d  ¡ƒV  qdS )r   NrH   )rN   Úrowr   r   r   Ú	<genexpr>ƒ   s   €  zCsearch_packages_info.<locals>._files_from_record.<locals>.<genexpr>)Ú	read_textÚFileNotFoundErrorÚcsvÚreaderÚ
splitlines)rO   Útextr   r   r   Ú_files_from_record}   s   ÿz0search_packages_info.<locals>._files_from_recordc                    s¢   z|   d¡}W n
 ty   Y d S w dd„ |jdd�D ƒ}| j}| j}|d u s+|d u r-|S z
t |¡ |¡‰ W n tyB   | Y S w ˆ j	sH|S ‡ fdd„|D ƒS )Nzinstalled-files.txtc                 s   s   � | ]}|r|V  qd S ©Nr   ©rN   Úpr   r   r   rb   Š   s   € zCsearch_packages_info.<locals>._files_from_legacy.<locals>.<genexpr>F©Úkeependsc                 3   s$   � | ]}t t |¡jˆ jƒV  qd S rj   )rK   rI   rJ   Úpartsrk   ©Zinfo_relr   r   rb   •   s
   € ÿ
ÿ)
rc   rd   rg   r6   Úinfo_directoryrI   rJ   Úrelative_toÚ
ValueErrorro   )rO   rh   ÚpathsÚrootrD   r   rp   r   Ú_files_from_legacy…   s(   ÿÿ
þz0search_packages_info.<locals>._files_from_legacyzentry_points.txtFrm   NÚ c                 S   s   g | ]}|j ‘qS r   )r4   )rN   Úreqr   r   r   rQ   ²   s    Ú
ClassifierZSummaryz	Home-pageZAuthorzAuthor-emailZLicense)r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   r   )r   Úiter_distributionsÚsortedÚzipr$   r%   Újoinr   r   r1   r   r   ÚKeyErrorrc   rg   rd   r\   r3   Úraw_namer5   r6   r[   r9   r:   Úget_allÚget)r(   ÚenvZquery_namesÚmissingr_   ri   rv   Z
query_namerO   Zentry_points_textrA   Z
files_iterr   r\   r   rS   r   r&   `   sb   €þÿ	ÿ
ÿ






ñìr&   Údistributionsr"   r#   c           	      C   sH  d}t | ƒD ]›\}}d}|dkrtdƒ td|jƒ td|jƒ td|jƒ td|jƒ td	|jƒ td
|jƒ td|jƒ td|j	ƒ tdd 
|j¡ƒ tdd 
|j¡ƒ |r„td|jƒ td|jƒ tdƒ |jD ]}td|ƒ qktdƒ |jD ]	}td| ¡ ƒ qz|r¡tdƒ |jdu r”tdƒ q|jD ]	}td| ¡ ƒ q—q|S )zC
    Print the information from installed distributions found.
    FTr   z---zName: %szVersion: %szSummary: %szHome-page: %sz
Author: %szAuthor-email: %szLicense: %szLocation: %szRequires: %srU   zRequired-by: %szMetadata-Version: %szInstaller: %szClassifiers:z  %szEntry-points:zFiles:Nz+Cannot locate RECORD or installed-files.txt)Ú	enumerater   r4   r5   r<   r=   r>   r?   r@   r6   r}   r7   r8   r:   r9   r;   rA   Ústripr   )	r„   r"   r#   Zresults_printedÚirO   Ú
classifierrC   Úliner   r   r   r'   Á   s@   




€r'   )!re   ÚloggingrI   Úoptparser   Útypingr   r   r   r   r   Úpip._vendor.packaging.utilsr	   Úpip._internal.cli.base_commandr
   Úpip._internal.cli.status_codesr   r   Úpip._internal.metadatar   r   Úpip._internal.utils.miscr   Ú	getLoggerr+   r$   r   r3   r1   rK   r&   Úboolr'   r   r   r   r   Ú<module>   s0    
"&aÿþýü