Skip to content

Commit

Permalink
fix: workaround unsupported metadata version 2.4 in pkginfo
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Dec 2, 2024
1 parent cdfd955 commit 7fe24cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 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.11"
platformdirs = ">=3.0.0,<5"
pyproject-hooks = "^1.0.0"
requests = "^2.26"
Expand Down
19 changes: 16 additions & 3 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import glob
import logging
import tempfile
import warnings

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import pkginfo

from pkginfo.distribution import NewMetadataVersion
from poetry.core.constraints.version import Version
from poetry.core.factory import Factory
from poetry.core.packages.dependency import Dependency
Expand Down Expand Up @@ -265,7 +267,10 @@ def _from_distribution(
:param dist: The distribution instance to parse information from.
"""
if dist.metadata_version not in pkginfo.distribution.HEADER_ATTRS:
# 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
raise ValueError(f"Unknown metadata version: {dist.metadata_version}")
Expand Down Expand Up @@ -389,7 +394,11 @@ def from_metadata_directory(cls, path: Path) -> PackageInfo | None:
if directory.suffix == ".egg-info":
dist = pkginfo.UnpackedSDist(directory.as_posix())
elif directory.suffix == ".dist-info":
dist = pkginfo.Wheel(directory.as_posix())
with warnings.catch_warnings():
# Filtering the NewMetadataVersion can be remove once pkginfo
# supports MetadataVersion 2.4.
warnings.simplefilter("ignore", NewMetadataVersion)
dist = pkginfo.Wheel(directory.as_posix())
else:
continue
break
Expand Down Expand Up @@ -489,7 +498,11 @@ def from_wheel(cls, path: Path) -> PackageInfo:
:param path: Path to wheel.
"""
try:
wheel = pkginfo.Wheel(str(path))
with warnings.catch_warnings():
# Filtering the NewMetadataVersion can be remove once pkginfo
# supports MetadataVersion 2.4.
warnings.simplefilter("ignore", NewMetadataVersion)
wheel = pkginfo.Wheel(str(path))
return cls._from_distribution(wheel)
except ValueError as e:
raise PackageInfoError(path, e)
Expand Down
3 changes: 1 addition & 2 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from build import BuildBackendException
from build import ProjectBuilder
from packaging.metadata import parse_email
from pkginfo.distribution import NewMetadataVersion

from poetry.inspection.info import PackageInfo
from poetry.inspection.info import PackageInfoError
Expand Down Expand Up @@ -221,7 +220,7 @@ def test_info_from_wheel_metadata_version_unknown(
/ "demo_metadata_version_unknown-0.1.0-py2.py3-none-any.whl"
)

with pytest.warns(NewMetadataVersion), pytest.raises(PackageInfoError) as e:
with pytest.raises(PackageInfoError) as e:
PackageInfo.from_wheel(path)

assert "Unknown metadata version: 999.3" in str(e.value)
Expand Down

0 comments on commit 7fe24cd

Please sign in to comment.