Skip to content

Commit

Permalink
Merge pull request #432 from FFY00/gh-428
Browse files Browse the repository at this point in the history
Add missing modules to packages_distributions
  • Loading branch information
jaraco authored Mar 18, 2023
2 parents b944c37 + df7824b commit 66e8e9b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v6.1.0
======

* #428: ``packages_distributions`` now honors packages and modules
with Python modules that not ``.py`` sources (e.g. ``.pyc``,
``.so``).

v6.0.1
======

Expand Down
7 changes: 4 additions & 3 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import itertools
import posixpath
import collections
import inspect

from . import _adapters, _meta, _py39compat
from ._collections import FreezableDefaultDict, Pair
Expand Down Expand Up @@ -897,8 +898,8 @@ def _top_level_declared(dist):


def _top_level_inferred(dist):
return {
f.parts[0] if len(f.parts) > 1 else f.with_suffix('').name
opt_names = {
f.parts[0] if len(f.parts) > 1 else inspect.getmodulename(f)
for f in always_iterable(dist.files)
if f.suffix == ".py"
}
return filter(None, opt_names)
31 changes: 31 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,34 @@ def test_packages_distributions_neither_toplevel_nor_files(self):
prefix=self.site_dir,
)
packages_distributions()

def test_packages_distributions_all_module_types(self):
"""
Test top-level modules detected on a package without 'top-level.txt'.
"""
suffixes = importlib.machinery.all_suffixes()
fixtures.build_files(
{
'all_distributions-1.0.0.dist-info': {
'METADATA': """
Name: all_distributions
Version: 1.0.0
""",
'RECORD': ''.join(
f'{i}-top-level{suffix},,\n'
f'{i}-in-namespace/mod{suffix},,\n'
f'{i}-in-package/__init__.py,,\n'
f'{i}-in-package/mod{suffix},,\n'
for i, suffix in enumerate(suffixes)
),
},
},
prefix=self.site_dir,
)

distributions = packages_distributions()

for i in range(len(suffixes)):
assert distributions[f'{i}-top-level'] == ['all_distributions']
assert distributions[f'{i}-in-namespace'] == ['all_distributions']
assert distributions[f'{i}-in-package'] == ['all_distributions']

0 comments on commit 66e8e9b

Please sign in to comment.