chore: use package_distributions
to get top levels
#861
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
docs
is updatedDescription of changes
Those changes are extracted from #854, as a first step towards using
importlib.metadata
/importlib_metadata
to remove some custom code we have, and make "package" <-> "distribution" discovery more precise.Python 3.10 introduced
packages_distributions
that returns a mapping that maps Python module names to the packages that expose them, by reading fromtop_level.txt
like we do. In Python 3.11, the method became even smarter by falling back to reading fromRECORD
when notop_level.txt
is present, also exactly like we do.Updates in
importlib.metadata
are upstreamed fromimportlib_metadata
, so by requiring>=4.13
on Python < 3.11, we could usepackages_distributions
in all Python versions we support, and also benefit from the improvement made on Python 3.11.There is one functional change in behaviour with the new implementation, which IMO makes sense to have. Currently, if a package has a
RECORD
file, but we don't match any Python module name in the file, we don't use the fallback that assumes the module name is the name with_
instead of-
. With the changes, we will now use the fall back if there was no match inRECORD
.Test plan