Skip to content

Commit

Permalink
Merge pull request #12291 from chrysle/pip-show-handle-env-markers
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Feb 24, 2024
2 parents e21c1df + 267716f commit 6e191e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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 @@ -361,3 +361,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

0 comments on commit 6e191e8

Please sign in to comment.