Skip to content

Commit ccd7be1

Browse files
pradyunsgsbidoul
andauthored
Change the source of truth for pkg_resources' extras (#12711)
* Change the source of truth for `pkg_resources`' extras Instead of relying on the METADATA file, use the `requires.txt` file that pkg_resources uses under the hood to get the "target" extra names to pass into `pkg_resources`. * Add failing test for issue 12688 --------- Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com> Co-authored-by: Stéphane Bidoul <stephane.bidoul@gmail.com>
1 parent 1a55574 commit ccd7be1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

news/12688.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Accommodate for mismatches between different sources of truth for extra names, for packages generated by ``setuptools``.

src/pip/_internal/metadata/pkg_resources.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Mapping,
1212
NamedTuple,
1313
Optional,
14-
cast,
1514
)
1615

1716
from pip._vendor import pkg_resources
@@ -92,8 +91,7 @@ def __init__(self, dist: pkg_resources.Distribution) -> None:
9291
def _extra_mapping(self) -> Mapping[NormalizedName, str]:
9392
if self.__extra_mapping is None:
9493
self.__extra_mapping = {
95-
canonicalize_name(extra): pkg_resources.safe_extra(cast(str, extra))
96-
for extra in self.metadata.get_all("Provides-Extra", [])
94+
canonicalize_name(extra): extra for extra in self._dist.extras
9795
}
9896

9997
return self.__extra_mapping

tests/functional/test_install_extras.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import textwrap
33
from os.path import join
4+
from pathlib import Path
45

56
import pytest
67

@@ -252,3 +253,23 @@ def test_install_extras(script: PipTestEnvironment) -> None:
252253
"a",
253254
)
254255
script.assert_installed(a="1", b="1", dep="1", meh="1")
256+
257+
258+
def test_install_setuptools_extras_inconsistency(
259+
script: PipTestEnvironment, tmp_path: Path
260+
) -> None:
261+
test_project_path = tmp_path.joinpath("test")
262+
test_project_path.mkdir()
263+
test_project_path.joinpath("setup.py").write_text(
264+
textwrap.dedent(
265+
"""
266+
from setuptools import setup
267+
setup(
268+
name='test',
269+
version='0.1',
270+
extras_require={'extra_underscored': ['packaging']},
271+
)
272+
"""
273+
)
274+
)
275+
script.pip("install", "--dry-run", test_project_path)

0 commit comments

Comments
 (0)