handle more varied top_level.txt files in distributions
Deal with distributions that do not have the top_level.txt metadata file, or that have more than one module name listed in it. Change-Id: I7d21f4ba674ee95d072b0bc8e5f22b5b4b7a32b4 Closes-Bug: #1719465 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
8b77ece17b
commit
a9719bc23e
|
@ -36,12 +36,17 @@ def _get_distributions_by_modules():
|
|||
results = {}
|
||||
for dist in pkg_resources.working_set:
|
||||
try:
|
||||
mod_name = dist.get_metadata('top_level.txt').strip()
|
||||
except KeyError:
|
||||
# Could not retrieve metadata. Ignore.
|
||||
mod_names = dist.get_metadata('top_level.txt').strip()
|
||||
except Exception:
|
||||
# Could not retrieve metadata. Either the file is not
|
||||
# present or we cannot read it. Ignore the
|
||||
# distribution.
|
||||
pass
|
||||
else:
|
||||
results[mod_name] = dist.project_name
|
||||
# Distributions may include multiple top-level
|
||||
# packages (see setuptools for an example).
|
||||
for mod_name in mod_names.splitlines():
|
||||
results[mod_name] = dist.project_name
|
||||
_dists_by_mods = results
|
||||
return _dists_by_mods
|
||||
|
||||
|
|
Loading…
Reference in New Issue