Skip to content

Commit

Permalink
inspection: error on unsupported metadata versions
Browse files Browse the repository at this point in the history
Resolves: #9195
  • Loading branch information
abn committed Mar 22, 2024
1 parent 36bf325 commit 4e749a0
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 @@ -226,6 +226,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 @@ -199,6 +199,20 @@ def test_info_from_wheel_metadata_version_23(fixture_dir: FixtureDirGetter) -> N
assert info._source_url == path.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 4e749a0

Please sign in to comment.