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: 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 valid_module(name):
return name.isidentifier()

return filter(valid_module, opt_names)
19 changes: 12 additions & 7 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ def test_packages_distributions_all_module_types(self):
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'
f'top_level_{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 +350,11 @@ 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'top_level_{i}'] == ['all_distributions']
assert distributions[f'in_namespace_{i}'] == ['all_distributions']
assert distributions[f'in_package_{i}'] == ['all_distributions']

# All keys return from packages_distributions() should be valid
# import names, which means that they must _at least_ be valid
# identifiers:
assert all(import_name.isidentifier() for import_name in distributions.keys())
jaraco marked this conversation as resolved.
Show resolved Hide resolved