We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 43afaeb commit 1a8e808Copy full SHA for 1a8e808
importlib_metadata/__init__.py
@@ -1013,6 +1013,18 @@ def packages_distributions() -> Mapping[str, List[str]]:
1013
"""
1014
pkg_to_dist = collections.defaultdict(list)
1015
for dist in distributions():
1016
- for pkg in (dist.read_text('top_level.txt') or '').split():
+ for pkg in _top_level_declared(dist) or _top_level_inferred(dist):
1017
pkg_to_dist[pkg].append(dist.metadata['Name'])
1018
return dict(pkg_to_dist)
1019
+
1020
1021
+def _top_level_declared(dist):
1022
+ return (dist.read_text('top_level.txt') or '').split()
1023
1024
1025
+def _top_level_inferred(dist):
1026
+ return {
1027
+ f.parts[0] if len(f.parts) > 1 else f.with_suffix('').name
1028
+ for f in dist.files
1029
+ if f.suffix == ".py"
1030
+ }
0 commit comments