This commit is contained in:
chrysle 2023-11-14 20:27:26 +01:00 committed by GitHub
commit 15d671ac74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

1
news/12165.bugfix.rst Normal file
View File

@ -0,0 +1 @@
This change will deduplicate entries in the ``Requires`` field of ``pip show``.

View File

@ -100,7 +100,11 @@ def search_packages_info(query: List[str]) -> Generator[_PackageInfo, None, None
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:

View File

@ -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