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 23, 2024
1 parent 23612d4 commit 2a2abce
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 @@ -266,6 +266,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 = cls._requirements_from_distribution(dist)

info = cls(
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 2a2abce

Please sign in to comment.