Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter excess entries #443

Merged
merged 11 commits into from
Apr 9, 2023
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v6.2.1
======

* #442: Fixed issue introduced in v6.1.0 where non-importable
names (metadata dirs) began appearing in
``packages_distributions``.

v6.2.0
======

Expand Down
7 changes: 6 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,9 @@ def _top_level_inferred(dist):
f.parts[0] if len(f.parts) > 1 else inspect.getmodulename(f)
for f in always_iterable(dist.files)
}
return filter(None, opt_names)

@pass_none
def importable_name(name):
return '.' not in name

return filter(importable_name, opt_names)
19 changes: 11 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,12 @@ def test_packages_distributions_all_module_types(self):
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'
'RECORD': 'all_distributions-1.0.0.dist-info/METADATA\n'
+ ''.join(
f'importable-name {i}{suffix},,\n'
f'in_namespace_{i}/mod{suffix},,\n'
f'in_package_{i}/__init__.py,,\n'
f'in_package_{i}/mod{suffix},,\n'
for i, suffix in enumerate(suffixes)
),
},
Expand All @@ -350,6 +351,8 @@ def test_packages_distributions_all_module_types(self):
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']
assert distributions[f'importable-name {i}'] == ['all_distributions']
assert distributions[f'in_namespace_{i}'] == ['all_distributions']
assert distributions[f'in_package_{i}'] == ['all_distributions']

assert not any(name.endswith('.dist-info') for name in distributions)