Skip to content

Commit 6e191e8

Browse files
authored
Merge pull request #12291 from chrysle/pip-show-handle-env-markers
2 parents e21c1df + 267716f commit 6e191e8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

news/12165.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This change will deduplicate entries in the ``Requires`` field of ``pip show``.

src/pip/_internal/commands/show.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
100100
except KeyError:
101101
continue
102102

103-
requires = sorted((req.name for req in dist.iter_dependencies()), key=str.lower)
103+
requires = sorted(
104+
# Avoid duplicates in requirements (e.g. due to environment markers).
105+
{req.name for req in dist.iter_dependencies()},
106+
key=str.lower,
107+
)
104108
required_by = sorted(_get_requiring_packages(dist), key=str.lower)
105109

106110
try:

tests/functional/test_show.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,29 @@ def test_show_include_work_dir_pkg(script: PipTestEnvironment) -> None:
361361
result = script.pip("show", "simple", cwd=pkg_path)
362362
lines = result.stdout.splitlines()
363363
assert "Name: simple" in lines
364+
365+
366+
def test_show_deduplicate_requirements(script: PipTestEnvironment) -> None:
367+
"""
368+
Test that show should deduplicate requirements
369+
for a package
370+
"""
371+
372+
# Create a test package and create .egg-info dir
373+
pkg_path = create_test_package_with_setup(
374+
script,
375+
name="simple",
376+
version="1.0",
377+
install_requires=[
378+
"pip >= 19.0.1",
379+
'pip >= 19.3.1; python_version < "3.8"',
380+
'pip >= 23.0.1; python_version < "3.9"',
381+
],
382+
)
383+
script.run("python", "setup.py", "egg_info", expect_stderr=True, cwd=pkg_path)
384+
385+
script.environ.update({"PYTHONPATH": pkg_path})
386+
387+
result = script.pip("show", "simple", cwd=pkg_path)
388+
lines = result.stdout.splitlines()
389+
assert "Requires: pip" in lines

0 commit comments

Comments
 (0)