Skip to content

Commit

Permalink
inspection: error on unsupported metadata versions
Browse files Browse the repository at this point in the history
Resolves: python-poetry#9195

(cherry picked from commit 2a2abce)
  • Loading branch information
abn authored and radoering committed Apr 12, 2024
1 parent c6af924 commit 717b6c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def _from_distribution(
:param dist: The distribution instance to parse information from.
"""
if dist.metadata_version not in pkginfo.distribution.HEADER_ATTRS:
# This check can be replaced once upstream implements strict parsing
# https://bugs.launchpad.net/pkginfo/+bug/2058697
raise ValueError("Unknown metadata version")

requirements = None

if dist.requires_dist:
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ def test_info_from_wheel(demo_wheel: Path) -> None:
assert info._source_url == demo_wheel.resolve().as_posix()


def test_info_from_wheel_metadata_version_unknown(
fixture_dir: FixtureDirGetter,
) -> None:
path = (
fixture_dir("distributions")
/ "demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl"
)

with pytest.raises(PackageInfoError) as e:
PackageInfo.from_wheel(path)

assert "Unknown metadata version" in str(e.value)


def test_info_from_wheel_metadata(demo_wheel_metadata: RawMetadata) -> None:
info = PackageInfo.from_metadata(demo_wheel_metadata)
demo_check_info(info)
Expand Down

0 comments on commit 717b6c3

Please sign in to comment.