diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 37c8b6b30cc..3fae1739c9b 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -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: diff --git a/tests/fixtures/distributions/demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl b/tests/fixtures/distributions/demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl new file mode 100644 index 00000000000..03988228fec Binary files /dev/null and b/tests/fixtures/distributions/demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl differ diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index a23e4879769..e88792c4d1d 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -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)