Skip to content

12446 - better error msg for missing METADATA file #13402

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/12446.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
improve error message shown when pkg.dist-info encounters a missing METADATA file
2 changes: 2 additions & 0 deletions src/pip/_internal/metadata/importlib/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def get_dist_canonical_name(dist: importlib.metadata.Distribution) -> Normalized
return canonicalize_name(name)

name = cast(Any, dist).name
if name is None:
raise BadMetadata(dist, reason="missing `METADATA` file")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't only get name equal to None when there's a missing METADATA file, we also get it when the .dist-info directory's name is incorrect - i.e., not in the form {name}-{version}.dist-info. There's also the possibility of a failure in get_info_location that isn't a missing METADATA file, as well as a .egg-info file with no stem (although that possibility seems very unlikely to me)

If we want to give a more informative message, we'll need to somehow distinguish the various possible failure cases in parse_name_and_version_from_info_directory.

if not isinstance(name, str):
raise BadMetadata(dist, reason="invalid metadata entry 'name'")
return canonicalize_name(name)
19 changes: 19 additions & 0 deletions tests/functional/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,22 @@ def test_list_wheel_build(script: PipTestEnvironment) -> None:
result = script.pip("list")
assert "Build" in result.stdout, str(result)
assert "123" in result.stdout, str(result)


def test_list_missing_metadata_warning(script: PipTestEnvironment) -> None:
"""
Test that a warning is shown when a dist-info directory is missing the
METADATA file.
"""
# Create a .dist-info dir without METADATA file
dist_info_path = script.site_packages_path / "foo-1.0.dist-info"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug report shows a reproducer that is missing the version and I can't reproduce this EXCEPT with an invalid .dist-info name. I think the initial bug report is in error. I will comment on the ticket itself.

dist_info_path.mkdir()

# pip list should warn about missing .dist-info/METADATA
result = script.pip("list", allow_stderr_warning=True)
print(str(result.stdout))
print(str(result.stderr))
print(dir(result))

assert "Skipping" in result.stderr
assert "missing `METADATA` file" in result.stderr
Loading