parameters: (query)
docstring: 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.
docstring_summary: 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.
docstring_tokens: 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 .
function: def search_packages_info(query):
      # type: (List[str]) -> Iterator[Dict[str, str]]
      """
      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.
      """
      installed = {}
      for p in pkg_resources.working_set:
          installed[canonicalize_name(p.project_name)] = p
  
      query_names = [canonicalize_name(name) for name in query]
      missing = sorted(
          [name for name, pkg in zip(query, query_names) if pkg not in installed]
      )
      if missing:
          logger.warning('Package(s) not found: %s', ', '.join(missing))
  
      def get_requiring_packages(package_name):
          # type: (str) -> List[str]
          canonical_name = canonicalize_name(package_name)
          return [
              pkg.project_name for pkg in pkg_resources.working_set
              if canonical_name in
                 [canonicalize_name(required.name) for required in
                  pkg.requires()]
          ]
  
      for dist in [installed[pkg] for pkg in query_names if pkg in installed]:
          package = {
              'name': dist.project_name,
              'version': dist.version,
              'location': dist.location,
              'requires': [dep.project_name for dep in dist.requires()],
              'required_by': get_requiring_packages(dist.project_name)
          }
          file_list = None
          metadata = ''
          if isinstance(dist, pkg_resources.DistInfoDistribution):
              # RECORDs should be part of .dist-info metadatas
              if dist.has_metadata('RECORD'):
                  lines = dist.get_metadata_lines('RECORD')
                  paths = [line.split(',')[0] for line in lines]
                  paths = [os.path.join(dist.location, p) for p in paths]
                  file_list = [os.path.relpath(p, dist.location) for p in paths]
  
              if dist.has_metadata('METADATA'):
                  metadata = dist.get_metadata('METADATA')
          else:
              # Otherwise use pip's log for .egg-info's
              if dist.has_metadata('installed-files.txt'):
                  paths = dist.get_metadata_lines('installed-files.txt')
                  paths = [os.path.join(dist.egg_info, p) for p in paths]
                  file_list = [os.path.relpath(p, dist.location) for p in paths]
  
              if dist.has_metadata('PKG-INFO'):
                  metadata = dist.get_metadata('PKG-INFO')
  
          if dist.has_metadata('entry_points.txt'):
              entry_points = dist.get_metadata_lines('entry_points.txt')
              package['entry_points'] = entry_points
  
          if dist.has_metadata('INSTALLER'):
              for line in dist.get_metadata_lines('INSTALLER'):
                  if line.strip():
                      package['installer'] = line.strip()
                      break
  
          # @todo: Should pkg_resources.Distribution have a
          # `get_pkg_info` method?
          feed_parser = FeedParser()
          feed_parser.feed(metadata)
          pkg_info_dict = feed_parser.close()
          for key in ('metadata-version', 'summary',
                      'home-page', 'author', 'author-email', 'license'):
              package[key] = pkg_info_dict.get(key)
  
          # It looks like FeedParser cannot deal with repeated headers
          classifiers = []
          for line in metadata.splitlines():
              if line.startswith('Classifier: '):
                  classifiers.append(line[len('Classifier: '):])
          package['classifiers'] = classifiers
  
          if file_list:
              package['files'] = sorted(file_list)
          yield package
function_tokens: def search_packages_info ( query ) : # type: (List[str]) -> Iterator[Dict[str, str]] installed = { } for p in pkg_resources . working_set : installed [ canonicalize_name ( p . project_name ) ] = p query_names = [ canonicalize_name ( name ) for name in query ] missing = sorted ( [ name for name , pkg in zip ( query , query_names ) if pkg not in installed ] ) if missing : logger . warning ( 'Package(s) not found: %s' , ', ' . join ( missing ) ) def get_requiring_packages ( package_name ) : # type: (str) -> List[str] canonical_name = canonicalize_name ( package_name ) return [ pkg . project_name for pkg in pkg_resources . working_set if canonical_name in [ canonicalize_name ( required . name ) for required in pkg . requires ( ) ] ] for dist in [ installed [ pkg ] for pkg in query_names if pkg in installed ] : package = { 'name' : dist . project_name , 'version' : dist . version , 'location' : dist . location , 'requires' : [ dep . project_name for dep in dist . requires ( ) ] , 'required_by' : get_requiring_packages ( dist . project_name ) } file_list = None metadata = '' if isinstance ( dist , pkg_resources . DistInfoDistribution ) : # RECORDs should be part of .dist-info metadatas if dist . has_metadata ( 'RECORD' ) : lines = dist . get_metadata_lines ( 'RECORD' ) paths = [ line . split ( ',' ) [ 0 ] for line in lines ] paths = [ os . path . join ( dist . location , p ) for p in paths ] file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] if dist . has_metadata ( 'METADATA' ) : metadata = dist . get_metadata ( 'METADATA' ) else : # Otherwise use pip's log for .egg-info's if dist . has_metadata ( 'installed-files.txt' ) : paths = dist . get_metadata_lines ( 'installed-files.txt' ) paths = [ os . path . join ( dist . egg_info , p ) for p in paths ] file_list = [ os . path . relpath ( p , dist . location ) for p in paths ] if dist . has_metadata ( 'PKG-INFO' ) : metadata = dist . get_metadata ( 'PKG-INFO' ) if dist . has_metadata ( 'entry_points.txt' ) : entry_points = dist . get_metadata_lines ( 'entry_points.txt' ) package [ 'entry_points' ] = entry_points if dist . has_metadata ( 'INSTALLER' ) : for line in dist . get_metadata_lines ( 'INSTALLER' ) : if line . strip ( ) : package [ 'installer' ] = line . strip ( ) break # @todo: Should pkg_resources.Distribution have a # `get_pkg_info` method? feed_parser = FeedParser ( ) feed_parser . feed ( metadata ) pkg_info_dict = feed_parser . close ( ) for key in ( 'metadata-version' , 'summary' , 'home-page' , 'author' , 'author-email' , 'license' ) : package [ key ] = pkg_info_dict . get ( key ) # It looks like FeedParser cannot deal with repeated headers classifiers = [ ] for line in metadata . splitlines ( ) : if line . startswith ( 'Classifier: ' ) : classifiers . append ( line [ len ( 'Classifier: ' ) : ] ) package [ 'classifiers' ] = classifiers if file_list : package [ 'files' ] = sorted ( file_list ) yield package