3 ig@sddlZddlZddlZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZmZddlmZmZddlmZejeZGd d d eZGd d d eZe ed fe ed fedddZeeeedddZeeeeedddZ dS)N)Values)IteratorList NamedTupleOptionalTuple)canonicalize_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|jjd|jdS) Nz-fz--filesfiles store_trueFz7Show the full list of installed files for each package.)destactiondefaulthelpr)cmd_opts add_optionparserinsert_option_group)selfr:/tmp/pip-build-88gy_88q/pip/pip/_internal/commands/show.py add_optionsszShowCommand.add_options)optionsargsrcCs8|stjdtS|}t|}t||j|jds4tStS)Nz.ERROR: Please provide a package name or names.) list_filesverbose)loggerwarningr search_packages_info print_resultsrr"r )rrr queryresultsrrrrun(s zShowCommand.run) __name__ __module__ __qualname____doc__usageZignore_require_venvrrrstrintr)rrrrrs  rc@sbeZdZUeeeeeee e e ee e eeeeeeeeedS) _PackageInfoN)r*r+r,r/nameversionlocationrrequires required_by installermetadata_version classifierssummaryhomepageauthor author_emaillicense entry_pointsrrrrrrr16s r1.)entryinforcCs\xH|rH|ddkrH| s$|ddkr.|d7}n |dd}|dd}qWttj||S)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..N)rBrD)r/pathlibPath)r@rArrr_convert_legacy_entryHs   rG)r'rc"#st}dd|jDdd|D}tfddt||D}|rXtjddj|ttt dfd d }tt tt d d d }tt tt d dd}x8|D].}y |}Wnt k rwYnXtdd|j Dt j d} t||t j d} y|jd} | jdd} Wntk r4g} YnX||pF||} | dkrXd}nt| }|j}t|jt |j|jp~d| | |j|jpd|jdg|jdd|jdd|jdd|jdd|jdd| |dVqWdS)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|] }||jqSr)canonical_name).0distrrr lsz(search_packages_info..cSsg|] }t|qSr)r)rIr2rrr msz(search_packages_info..csg|]\}}|kr|qSrr)rIr2pkg) installedrrrLoszPackage(s) not found: %sz, ) current_distrcsfddjDS)Nc3s4|],}jdd|jDkr|jdp*dVqdS)cSsh|]}t|jqSr)rr2)rIdrrr yszRsearch_packages_info.._get_requiring_packages...NameUNKNOWNN)rHiter_dependenciesmetadata)rIrJ)rOrr vszHsearch_packages_info.._get_requiring_packages..)values)rO)rN)rOr_get_requiring_packagests z5search_packages_info.._get_requiring_packages)rJrc Ss<y|jd}Wntk r"dSXddtj|jDS)NRECORDcss |]}ttj|dVqdS)rN)r/rErF)rIrowrrrrVszCsearch_packages_info.._files_from_record..) read_textFileNotFoundErrorcsvreader splitlines)rJtextrrr_files_from_record|s z0search_packages_info.._files_from_recordcsy|jd}Wntk r"dSXdd|jddD}|j}|j}|dksV|dkrZ|Sytj|j|Wntk r|SXj s|Sfdd|DS)Nzinstalled-files.txtcss|]}|r|VqdS)Nr)rIprrrrVszCsearch_packages_info.._files_from_legacy..F)keependsc3s"|]}ttj|jjVqdS)N)rGrErFparts)rIrb)info_relrrrVs) r[r\r_r4Zinfo_directoryrErFZ relative_to ValueErrorrd)rJr`pathsrootrAr)rer_files_from_legacys z0search_packages_info.._files_from_legacycss|] }|jVqdS)N)r2)rIreqrrrrVsz'search_packages_info..)keyzentry_points.txtF)rcN ClassifierZSummaryz Home-pageZAuthorz Author-emailZLicense)r2r3r4r5r6r7r8r9r:r;r<r=r>r?r)r Ziter_distributionssortedzipr#r$joinr rr/rKeyErrorrTlowerr[r_r\rUr1Zraw_namer3r4r7r8get_allget)r'env query_namesmissingrXrariZ query_namerJr5r6Zentry_points_textr?Z files_iterrrUr)rNrr%csV            r%) distributionsr!r"rc Csdd}xXt|D]J\}}d}|dkr.tdtd|jtd|jtd|jtd|jtd |jtd |jtd |jtd |j td dj |j tddj |j |rtd|j td|jtdx|jD]}td|qWtdx|jD]}td|jqW|rtd|jdkrr4rpr5r6r8r7r9r?stripr) rxr!r"results_printedirJ classifierr@linerrrr&s>               r&)!r]loggingrEoptparserZtypingrrrrrpip._vendor.packaging.utilsrZpip._internal.cli.base_commandr Zpip._internal.cli.status_codesr r Zpip._internal.metadatar r Zpip._internal.utils.miscr getLoggerr*r#rr1r/rGr%boolr&rrrrs$     %"`