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
Add missing modules to packages_distributions #432
Conversation
e456fcf
to
8d9bc40
Compare
Edge case I found: empty namespace packages, which are still importable, can't ever be reported with the current abstractions. I don't think this is a big issue though, https://github.com/pypa/installer also does not support creating empty directories, so people trying to ship packages containing such thing will likely get trouble trying to install them in the first place. |
Signed-off-by: Filipe Laíns <lains@riseup.net>
I wonder if this adds the metadata directories into the output of
IMHO, these should never occur here, as they are not importable modules. |
Confirmed by applying this diff to the test added in this PR; the important stuff is in the last 4 lines, but I first needed to change the existing dummy module names into valid import names (== valid Python identifiers): diff --git a/tests/test_main.py b/tests/test_main.py
index 1636779..d448e6c 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -336,10 +336,10 @@ class PackagesDistributionsTest(
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)
),
},
@@ -350,6 +350,11 @@ class PackagesDistributionsTest(
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 returned from packages_distributions() should be valid import
+ # names, which means that they must _at least_ be valid identifiers:
+ for import_name in distributions.keys():
+ assert import_name.isidentifier(), import_name |
I wonder if the final |
I came here to say the same thing as @jherland. The introduction of To reproduce:
$ python -m pip list
Package Version
------------------ -------
importlib-metadata 6.1.0
pip 21.2.3
setuptools 57.4.0
wheel 0.40.0
zipp 3.15.0 $ python -c "import importlib_metadata;print(importlib_metadata.packages_distributions())"
{'_distutils_hack': ['setuptools'], 'pkg_resources': ['setuptools'], 'setuptools': ['setuptools'], 'zipp': ['zipp'], 'wheel-0.40.0.dist-info': ['wheel'], 'wheel': ['wheel'], '..': ['wheel'], 'pip': ['pip'], 'importlib_metadata': ['importlib-metadata']} |
This now considers:
.py
prefix (eg. native modules,.pyc
-only modules).py
files insideWhich I think should be all possible modules, right?
Fix #428