Skip to content

Commit

Permalink
info: require pkginfo >= 1.12 for METADATA 2.4 support and loosen c…
Browse files Browse the repository at this point in the history
…heck for unknown METADATA versions (python-poetry#9888)
  • Loading branch information
radoering authored Dec 6, 2024
1 parent bd4adcb commit a3cae0c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ installer = "^0.7.0"
keyring = "^25.1.0"
# packaging uses calver, so version is unclamped
packaging = ">=24.0"
pkginfo = "^1.10"
pkginfo = "^1.12"
platformdirs = ">=3.0.0,<5"
pyproject-hooks = "^1.0.0"
requests = "^2.26"
Expand Down
13 changes: 7 additions & 6 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ def _from_distribution(
:param dist: The distribution instance to parse information from.
"""
# The current pkginfo version (1.11.2) does not support 2.4.
# The fields we are interested in can be parsed nevertheless.
supported_metadata_versions = {*pkginfo.distribution.HEADER_ATTRS.keys(), "2.4"}
if dist.metadata_version not in supported_metadata_versions:
# This check can be replaced once upstream implements strict parsing
# https://bugs.launchpad.net/pkginfo/+bug/2058697
# If the METADATA version is greater than the highest supported version,
# pkginfo prints a warning and tries to parse the fields from the highest
# known version. Assuming that METADATA versions adhere to semver,
# this should be safe for minor updates.
if not dist.metadata_version or dist.metadata_version.split(".")[0] not in {
v.split(".")[0] for v in pkginfo.distribution.HEADER_ATTRS
}:
raise ValueError(f"Unknown metadata version: {dist.metadata_version}")

requirements = cls._requirements_from_distribution(dist)
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_info_from_wheel(demo_wheel: Path) -> None:
assert info._source_url == demo_wheel.resolve().as_posix()


@pytest.mark.parametrize("version", ["23", "24"])
@pytest.mark.parametrize("version", ["23", "24", "299"])
def test_info_from_wheel_metadata_versions(
version: str, fixture_dir: FixtureDirGetter
) -> None:
Expand Down

0 comments on commit a3cae0c

Please sign in to comment.