def pypi(b, r):
    logging.info('searching for Python packages')

    # Look for packages in the typical places.  `pip` has its `freeze`
    # subcommand but there is no way but diving into the directory tree to
    # figure out what packages were `easy_install`ed.  If `VIRTUAL_ENV`
    # appears in the environment, treat the directory it names just like
    # the global package directories.
    globnames = ['/usr/lib/python*/dist-packages',
                 '/usr/lib/python*/site-packages',
                 '/usr/local/lib/python*/dist-packages',
                 '/usr/local/lib/python*/site-packages']
    virtualenv = os.getenv('VIRTUAL_ENV')
    if virtualenv is not None:
        globnames.extend(['{0}/lib/python*/dist-packages'.format(virtualenv),
                          '{0}/lib/python*/dist-packages'.format(virtualenv)])
    for globname in globnames:
        for dirname in glob.glob(globname):
            manager = pattern_manager.search(dirname).group(1)
            for entry in os.listdir(dirname):
                match = pattern.match(entry)
                if match is None:
                    continue
                package, version = match.group(1, 2)
                pathname = os.path.join(dirname, entry)

                # Symbolic links indicate this is actually a system package
                # that injects files into the PYTHONPATH.
                if os.path.islink(pathname):
                    continue

                # Assume this is a Debian-based system and let `OSError`
                # looking for `dpkg-query` prove this is RPM-based.  In
                # that case, the dependencies get a bit simpler.
                try:
                    _dpkg_query(b, r,
                                manager, package, version,
                                entry, pathname)
                except __HOLE__:
                    try:
                        _rpm(b, r, manager, package, version, entry, pathname)
                    except OSError:
                        logging.warning('neither dpkg nor rpm found')
dataset/ETHPy150Open devstructure/blueprint/blueprint/backend/pypi.py/pypi