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 (#9888)

(cherry picked from commit a3cae0c)
  • Loading branch information
radoering committed Dec 6, 2024
1 parent 6a071c1 commit 2562ad3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
10 changes: 5 additions & 5 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 @@ -45,7 +45,7 @@ keyring = "^24.0.0"
# packaging uses calver, so version is unclamped
packaging = ">=23.1"
pexpect = "^4.7.0"
pkginfo = "^1.10"
pkginfo = "^1.12"
platformdirs = ">=3.0.0,<5"
pyproject-hooks = "^1.0.0"
requests = "^2.26"
Expand Down
10 changes: 7 additions & 3 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ 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
# 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 = None
Expand Down
Binary file not shown.
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 @@ -179,6 +179,20 @@ def test_info_from_wheel(demo_wheel: Path) -> None:
assert info._source_url == demo_wheel.resolve().as_posix()


@pytest.mark.parametrize("version", ["24", "299"])
def test_info_from_wheel_metadata_versions(
version: str, fixture_dir: FixtureDirGetter
) -> None:
path = (
fixture_dir("distributions")
/ f"demo_metadata_version_{version}-0.1.0-py2.py3-none-any.whl"
)
info = PackageInfo.from_wheel(path)
demo_check_info(info)
assert info._source_type == "file"
assert info._source_url == path.resolve().as_posix()


def test_info_from_wheel_metadata_version_unknown(
fixture_dir: FixtureDirGetter,
) -> None:
Expand Down

0 comments on commit 2562ad3

Please sign in to comment.