Skip to content

Commit cb4ded8

Browse files
committed
info: require pkginfo >= 1.12 for METADATA 2.4 support and loosen check for unknown METADATA versions (python-poetry#9888)
(cherry picked from commit a3cae0c)
1 parent 6a071c1 commit cb4ded8

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ keyring = "^24.0.0"
4545
# packaging uses calver, so version is unclamped
4646
packaging = ">=23.1"
4747
pexpect = "^4.7.0"
48-
pkginfo = "^1.10"
48+
pkginfo = "^1.12"
4949
platformdirs = ">=3.0.0,<5"
5050
pyproject-hooks = "^1.0.0"
5151
requests = "^2.26"

src/poetry/inspection/info.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,13 @@ def _from_distribution(
245245
246246
:param dist: The distribution instance to parse information from.
247247
"""
248-
if dist.metadata_version not in pkginfo.distribution.HEADER_ATTRS:
249-
# This check can be replaced once upstream implements strict parsing
250-
# https://bugs.launchpad.net/pkginfo/+bug/2058697
248+
# If the METADATA version is greater than the highest supported version,
249+
# pkginfo prints a warning and tries to parse the fields from the highest
250+
# known version. Assuming that METADATA versions adhere to semver,
251+
# this should be safe for minor updates.
252+
if not dist.metadata_version or dist.metadata_version.split(".")[0] not in {
253+
v.split(".")[0] for v in pkginfo.distribution.HEADER_ATTRS
254+
}:
251255
raise ValueError(f"Unknown metadata version: {dist.metadata_version}")
252256

253257
requirements = None
Binary file not shown.
Binary file not shown.

tests/inspection/test_info.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ def test_info_from_wheel(demo_wheel: Path) -> None:
179179
assert info._source_url == demo_wheel.resolve().as_posix()
180180

181181

182+
@pytest.mark.parametrize("version", ["24", "299"])
183+
def test_info_from_wheel_metadata_versions(
184+
version: str, fixture_dir: FixtureDirGetter
185+
) -> None:
186+
path = (
187+
fixture_dir("distributions")
188+
/ f"demo_metadata_version_{version}-0.1.0-py2.py3-none-any.whl"
189+
)
190+
info = PackageInfo.from_wheel(path)
191+
demo_check_info(info)
192+
assert info._source_type == "file"
193+
assert info._source_url == path.resolve().as_posix()
194+
195+
182196
def test_info_from_wheel_metadata_version_unknown(
183197
fixture_dir: FixtureDirGetter,
184198
) -> None:

0 commit comments

Comments
 (0)