Skip to content

Handle malformed version metadata error and skip the package #13513

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 8 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
2 changes: 2 additions & 0 deletions news/13443.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Handle malformed ``Version`` metadata entries and
show a sensible error message instead of crashing.
10 changes: 8 additions & 2 deletions src/pip/_internal/metadata/importlib/_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file

from ._compat import (
BadMetadata,
BasePath,
get_dist_canonical_name,
parse_name_and_version_from_info_directory,
Expand Down Expand Up @@ -165,9 +166,14 @@ def canonical_name(self) -> NormalizedName:

@property
def version(self) -> Version:
if version := parse_name_and_version_from_info_directory(self._dist)[1]:
try:
version = (
parse_name_and_version_from_info_directory(self._dist)[1]
or self._dist.version
)
return parse_version(version)
return parse_version(self._dist.version)
except TypeError:
raise BadMetadata(self._dist, reason="invalid metadata entry `version`")

@property
def raw_version(self) -> str:
Expand Down
Loading