a [f@sddlZddlZddlZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZmZddlmZmZddlmZeeZGd d d eZGd d d eZe ed fe ed fedddZeeeedddZeeeeedddZ dS)N)Values)IteratorList NamedTupleOptionalTuplecanonicalize_name)Command)ERRORSUCCESS)BaseDistributionget_default_environment) write_outputc@s<eZdZdZdZdZddddZeee e dd d Z dS) ShowCommandzx Show information about one or more installed packages. The output is in RFC-compliant mail header format. z$ %prog [options] ...TN)returncCs,|jjddddddd|jd|jdS) Nz-fz--filesfiles store_trueFz7Show the full list of installed files for each package.)destactiondefaulthelpr)Zcmd_optsZ add_optionparserZinsert_option_group)selfr?/usr/lib/python3.9/site-packages/pip/_internal/commands/show.py add_optionss zShowCommand.add_options)optionsargsrcCs8|stdtS|}t|}t||j|jds4tStS)Nz.ERROR: Please provide a package name or names.) list_filesverbose)loggerwarningr search_packages_info print_resultsrr r )rrrqueryresultsrrrrun(s  zShowCommand.run) __name__ __module__ __qualname____doc__usageZignore_require_venvrrrstrintr'rrrrrs  rc@seZdZUeed<eed<eed<eeed<eeed<eed<eed<eeed<eed <eed <eed <eed <eed <eeed<eeeed<dS) _PackageInfonameversionlocationrequires required_by installermetadata_version classifierssummaryhomepageauthor author_emaillicense entry_pointsrN)r(r)r*r-__annotations__rrrrrrr/6s     r/.)entryinforcCs\|rD|ddkrD|r |ddkr*|d7}n |dd}|dd}qttjg||RS)aConvert 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..)rANr-pathlibPath)r?r@rrr_convert_legacy_entryHs   rG)r%rc#st}dd|Ddd|D}tfddt||D}|rXtdd|ttt dfd d }tt tt d d d }tt tt d dd}|D],}z |}Wnt yYqYn0tdd| Dt j d} t||t j d} z|d} | jdd} Wnty.g} Yn0||p@||} | durRd}nt| }|j}t|jt |j|jpxd| | |j|jpd|dg|dd|dd|dd|dd|dd| |dVqdS)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. cSsi|] }|j|qSr)canonical_name.0distrrr lz(search_packages_info..cSsg|] }t|qSrr)rJr0rrr mrMz(search_packages_info..csg|]\}}|vr|qSrr)rJr0pkgZ installedrrrNorMzPackage(s) not found: %s, ) current_distrcsfddDS)Nc3s4|],}jdd|Dvr|jdp*dVqdS)cSsh|]}t|jqSr)r r0)rJdrrr yrMzRsearch_packages_info.._get_requiring_packages...NameZUNKNOWNN)rHiter_dependenciesmetadatarIrRrr us zHsearch_packages_info.._get_requiring_packages..)valuesrXrPrXr_get_requiring_packagests z5search_packages_info.._get_requiring_packages)rKrcSs<z|d}Wnty"YdS0ddt|DS)NZRECORDcss |]}tt|dVqdS)rNrD)rJrowrrrrYrMzCsearch_packages_info.._files_from_record..) read_textFileNotFoundErrorcsvreader splitlines)rKtextrrr_files_from_record|s  z0search_packages_info.._files_from_recordcsz|d}Wnty"YdS0dd|jddD}|j}|j}|dusV|durZ|Szt||Wnty|YS0j s|Sfdd|DS)Nzinstalled-files.txtcss|]}|r|VqdSNrrJprrrrYrMzCsearch_packages_info.._files_from_legacy..Fkeependsc3s"|]}tt|jjVqdSrd)rGrErFpartsreZinfo_relrrrYs) r]r^rar2Zinfo_directoryrErF relative_to ValueErrorri)rKrbpathsrootr@rrjr_files_from_legacys$    z0search_packages_info.._files_from_legacycss|] }|jVqdSrd)r0)rJZreqrrrrYrMz'search_packages_info..)keyzentry_points.txtFrgNZ ClassifierZSummaryz Home-pageZAuthorz Author-emailZLicense)r0r1r2r3r4r5r6r7r8r9r:r;r<r=r)rZiter_distributionssortedzipr!r"joinr rr-rKeyErrorrVlowerr]rar^rWr/Zraw_namer1r2r5r6Zget_allget)r%envZ query_namesmissingr[rcroZ query_namerKr3r4Zentry_points_textr=Z files_iterrrWrrPrr#csZ               r#) distributionsrr rc CsPd}t|D]<\}}d}|dkr*tdtd|jtd|jtd|jtd|jtd |jtd |jtd |jtd |j td d |j tdd |j |r td|j td|jtd|jD]}td|qtd|jD]}td|q|r td|jdur.tdq |jD]}td|q4q |S)zC Print the information from installed distributions found. FTrz---zName: %sz Version: %sz Summary: %sz Home-page: %sz Author: %szAuthor-email: %sz License: %sz Location: %sz Requires: %srQzRequired-by: %szMetadata-Version: %sz Installer: %sz Classifiers:z %sz Entry-points:zFiles:Nz+Cannot locate RECORD or installed-files.txt) enumeraterr0r1r8r9r:r;r<r2rtr3r4r6r5r7r=stripr) rzrr Zresults_printedirKZ classifierr?linerrrr$s>                r$)!r_ZloggingrEZoptparsertypingrrrrrZpip._vendor.packaging.utilsr Zpip._internal.cli.base_commandr Zpip._internal.cli.status_codesr r Zpip._internal.metadatar rZpip._internal.utils.miscrZ getLoggerr(r!rr/r-rGr#boolr$rrrrs&     %"`