diff --git a/news/12688.bugfix.rst b/news/12688.bugfix.rst new file mode 100644 index 00000000000..72f8766baa3 --- /dev/null +++ b/news/12688.bugfix.rst @@ -0,0 +1 @@ +Accommodate for mismatches between different sources of truth for extra names, for packages generated by ``setuptools``. diff --git a/src/pip/_internal/metadata/pkg_resources.py b/src/pip/_internal/metadata/pkg_resources.py index 235556781c6..4ea84f93a6f 100644 --- a/src/pip/_internal/metadata/pkg_resources.py +++ b/src/pip/_internal/metadata/pkg_resources.py @@ -11,7 +11,6 @@ Mapping, NamedTuple, Optional, - cast, ) from pip._vendor import pkg_resources @@ -92,8 +91,7 @@ def __init__(self, dist: pkg_resources.Distribution) -> None: def _extra_mapping(self) -> Mapping[NormalizedName, str]: if self.__extra_mapping is None: self.__extra_mapping = { - canonicalize_name(extra): pkg_resources.safe_extra(cast(str, extra)) - for extra in self.metadata.get_all("Provides-Extra", []) + canonicalize_name(extra): extra for extra in self._dist.extras } return self.__extra_mapping diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py index 4dd27bb9df3..4e74f54a2c3 100644 --- a/tests/functional/test_install_extras.py +++ b/tests/functional/test_install_extras.py @@ -1,6 +1,7 @@ import re import textwrap from os.path import join +from pathlib import Path import pytest @@ -252,3 +253,23 @@ def test_install_extras(script: PipTestEnvironment) -> None: "a", ) script.assert_installed(a="1", b="1", dep="1", meh="1") + + +def test_install_setuptools_extras_inconsistency( + script: PipTestEnvironment, tmp_path: Path +) -> None: + test_project_path = tmp_path.joinpath("test") + test_project_path.mkdir() + test_project_path.joinpath("setup.py").write_text( + textwrap.dedent( + """ + from setuptools import setup + setup( + name='test', + version='0.1', + extras_require={'extra_underscored': ['packaging']}, + ) + """ + ) + ) + script.pip("install", "--dry-run", test_project_path)