Add a module_names attribute to importlib.metadata.Distribution

Hey! I’m a core developer on PyInstaller working on upgrading all our code from pkg_resources to the importlib API. While doing this, I found that importlib.metadata.Distribution provides some useful APIs regarding packages, however there seems to be no property on the class providing the actual top-level import name(s) of a distribution, and I’ve had to implement that functionality myself.

Ideally, this which shouldn’t be needed as importlib itself implements the same functionality in the packages_distributions function. Additionally, the logic behind the functionality is undocumented as far as I can tell - the importable module names are listed in name.dist-info/top_level.txt, a file only documented here - a document which describes a deprecated format - and in the pip changelog, which I’d link but I’m blocked from posting more than 2 links. If you search top_level.txt you’ll find it easily.).

As such, would there be any support or objections to me adding this functionality directly as a Distribution.module_names property? And if so, how would I go about this? Submit PRs to both importlib_metadata and CPython?

1 Like

The functionality in question is implemented here and also used here.

Looks related to Record the top-level names of a wheel in `METADATA`?