From 6740b0bd0fad7b2fb900547d37e6edbdae405dff Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 22 Mar 2024 23:39:58 +0100 Subject: [PATCH] inspection: error on unsupported metadata versions Resolves: #9195 (cherry picked from commit 2a2abce88d091891f8e7ca2159b943d15ae2e7c3) --- src/poetry/inspection/info.py | 5 +++++ ...ta_version_unknown-0.1.0-py2.py3-none-any.whl | Bin 0 -> 1153 bytes tests/inspection/test_info.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 tests/fixtures/distributions/demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl 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 0000000000000000000000000000000000000000..03988228fec381e1eb7267cbb8a549152ffdffee GIT binary patch literal 1153 zcmWIWW@Zs#W?Ke_98l9aHoi4WgZv)KB$_xKXRI1EB zEWUY3f|SMAZ>e?r^Pd^?KQVOgzo;Fl-YaGx*I#)iC`3g;J@tnD%a3;NH@XIJy>(;Q zZQixWRBY;xNp?&8^EGFm?Aemdlh;&l9(Lf-_w>$l-j@t`&n3HAi%fKi@n2$>C?!C;lHhzv{}t zbGrlPe=FGdRlI5Kq%CtTyyyAx7R;IXCtqPx4tHdbFWai(<eGA5L@q7F3{dy~2aG9-kbHSFmpVL^J zg9UrP35w)i+pV|bppH`OvgyxO?f5L1dy#ANvd{gxJC=Vva%jPkvo$d10PSW_WN6|l zd?^NGfv^A&gA%%ae0*kJW=VX!UO{Did|7Hyab|vAe7u6Kf;u=0sB;B)GcwsTXnrS literal 0 HcmV?d00001 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)