diff --git a/poetry.lock b/poetry.lock index b2689d4a90c..e4105d462fd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -925,13 +925,13 @@ ptyprocess = ">=0.5" [[package]] name = "pkginfo" -version = "1.10.0" +version = "1.12.0" description = "Query metadata from sdists / bdists / installed packages." optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "pkginfo-1.10.0-py3-none-any.whl", hash = "sha256:889a6da2ed7ffc58ab5b900d888ddce90bce912f2d2de1dc1c26f4cb9fe65097"}, - {file = "pkginfo-1.10.0.tar.gz", hash = "sha256:5df73835398d10db79f8eecd5cd86b1f6d29317589ea70796994d49399af6297"}, + {file = "pkginfo-1.12.0-py3-none-any.whl", hash = "sha256:dcd589c9be4da8973eceffa247733c144812759aa67eaf4bbf97016a02f39088"}, + {file = "pkginfo-1.12.0.tar.gz", hash = "sha256:8ad91a0445a036782b9366ef8b8c2c50291f83a553478ba8580c73d3215700cf"}, ] [package.extras] @@ -1618,4 +1618,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "e793d16c7f8a014e1fc36d16b280e271032f4b8cd152ede01638e61a7c6026d8" +content-hash = "b4f0da10f17e674f506b690ee799443cf9115fdf8b6fe96f8742ad19d5f8a503" diff --git a/pyproject.toml b/pyproject.toml index f83056f6ee0..59eb9be32bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 02cf66a2b35..747485e6dab 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -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 diff --git a/tests/fixtures/distributions/demo_metadata_version_24-0.1.0-py2.py3-none-any.whl b/tests/fixtures/distributions/demo_metadata_version_24-0.1.0-py2.py3-none-any.whl new file mode 100644 index 00000000000..4c8cf2f72b3 Binary files /dev/null and b/tests/fixtures/distributions/demo_metadata_version_24-0.1.0-py2.py3-none-any.whl differ diff --git a/tests/fixtures/distributions/demo_metadata_version_299-0.1.0-py2.py3-none-any.whl b/tests/fixtures/distributions/demo_metadata_version_299-0.1.0-py2.py3-none-any.whl new file mode 100644 index 00000000000..8523f2cbe1f Binary files /dev/null and b/tests/fixtures/distributions/demo_metadata_version_299-0.1.0-py2.py3-none-any.whl differ diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index 8e1ccf50fe9..c136cb763a1 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() +@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: