def search_packages_info(query):
installed = {}<EOL>for p in pkg_resources.working_set:<EOL><INDENT>installed[canonicalize_name(p.project_name)] = p<EOL><DEDENT>query_names = [canonicalize_name(name) for name in query]<EOL>for dist in [installed[pkg] for pkg in query_names if pkg in installed]:<EOL><INDENT>package = {<EOL>'<STR_LIT:name>': dist.project_name,<EOL>'<STR_LIT:version>': dist.version,<EOL>'<STR_LIT:location>': dist.location,<EOL>'<STR_LIT>': [dep.project_name for dep in dist.requires()],<EOL>}<EOL>file_list = None<EOL>metadata = None<EOL>if isinstance(dist, pkg_resources.DistInfoDistribution):<EOL><INDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>lines = dist.get_metadata_lines('<STR_LIT>')<EOL>paths = [l.split('<STR_LIT:U+002C>')[<NUM_LIT:0>] for l in lines]<EOL>paths = [os.path.join(dist.location, p) for p in paths]<EOL>file_list = [os.path.relpath(p, dist.location) for p in paths]<EOL><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>metadata = dist.get_metadata('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>paths = dist.get_metadata_lines('<STR_LIT>')<EOL>paths = [os.path.join(dist.egg_info, p) for p in paths]<EOL>file_list = [os.path.relpath(p, dist.location) for p in paths]<EOL><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>metadata = dist.get_metadata('<STR_LIT>')<EOL><DEDENT><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>entry_points = dist.get_metadata_lines('<STR_LIT>')<EOL>package['<STR_LIT>'] = entry_points<EOL><DEDENT>if dist.has_metadata('<STR_LIT>'):<EOL><INDENT>for line in dist.get_metadata_lines('<STR_LIT>'):<EOL><INDENT>if line.strip():<EOL><INDENT>package['<STR_LIT>'] = line.strip()<EOL>break<EOL><DEDENT><DEDENT><DEDENT>feed_parser = FeedParser()<EOL>feed_parser.feed(metadata)<EOL>pkg_info_dict = feed_parser.close()<EOL>for key in ('<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>package[key] = pkg_info_dict.get(key)<EOL><DEDENT>classifiers = []<EOL>for line in metadata.splitlines():<EOL><INDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>classifiers.append(line[len('<STR_LIT>'):])<EOL><DEDENT><DEDENT>package['<STR_LIT>'] = classifiers<EOL>if file_list:<EOL><INDENT>package['<STR_LIT>'] = sorted(file_list)<EOL><DEDENT>yield package<EOL><DEDENT>
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.