Skip to content

Deduplicate pip show output in Requires field #12291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/12165.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This change will deduplicate entries in the ``Requires`` field of ``pip show``.
6 changes: 5 additions & 1 deletion src/pip/_internal/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
except KeyError:
continue

requires = sorted((req.name for req in dist.iter_dependencies()), key=str.lower)
requires = sorted(
# Avoid duplicates in requirements (e.g. due to environment markers).
{req.name for req in dist.iter_dependencies()},
key=str.lower,
)
required_by = sorted(_get_requiring_packages(dist), key=str.lower)

try:
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,29 @@ def test_show_include_work_dir_pkg(script: PipTestEnvironment) -> None:
result = script.pip("show", "simple", cwd=pkg_path)
lines = result.stdout.splitlines()
assert "Name: simple" in lines


def test_show_deduplicate_requirements(script: PipTestEnvironment) -> None:
"""
Test that show should deduplicate requirements
for a package
"""

# Create a test package and create .egg-info dir
pkg_path = create_test_package_with_setup(
script,
name="simple",
version="1.0",
install_requires=[
"pip >= 19.0.1",
'pip >= 19.3.1; python_version < "3.8"',
'pip >= 23.0.1; python_version < "3.9"',
],
)
script.run("python", "setup.py", "egg_info", expect_stderr=True, cwd=pkg_path)

script.environ.update({"PYTHONPATH": pkg_path})

result = script.pip("show", "simple", cwd=pkg_path)
lines = result.stdout.splitlines()
assert "Requires: pip" in lines