Skip to content

Commit

Permalink
Merge pull request #10422 from aphedges/sort-show-requires
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Sep 21, 2021
2 parents 2ef2b0d + 3d72678 commit 0c86e3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/10422.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``pip show`` now sorts ``Requires`` and ``Required-By`` alphabetically.
13 changes: 8 additions & 5 deletions src/pip/_internal/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def search_packages_info(query: List[str]) -> Iterator[_PackageInfo]:
if missing:
logger.warning("Package(s) not found: %s", ", ".join(missing))

def _get_requiring_packages(current_dist: BaseDistribution) -> List[str]:
return [
def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
return (
dist.metadata["Name"] or "UNKNOWN"
for dist in installed.values()
if current_dist.canonical_name
in {canonicalize_name(d.name) for d in dist.iter_dependencies()}
]
)

def _files_from_record(dist: BaseDistribution) -> Optional[Iterator[str]]:
try:
Expand Down Expand Up @@ -155,6 +155,9 @@ def _files_from_legacy(dist: BaseDistribution) -> Optional[Iterator[str]]:
except KeyError:
continue

requires = sorted((req.name for req in dist.iter_dependencies()), key=str.lower)
required_by = sorted(_get_requiring_packages(dist), key=str.lower)

try:
entry_points_text = dist.read_text("entry_points.txt")
entry_points = entry_points_text.splitlines(keepends=False)
Expand All @@ -173,8 +176,8 @@ def _files_from_legacy(dist: BaseDistribution) -> Optional[Iterator[str]]:
name=dist.raw_name,
version=str(dist.version),
location=dist.location or "",
requires=[req.name for req in dist.iter_dependencies()],
required_by=_get_requiring_packages(dist),
requires=requires,
required_by=required_by,
installer=dist.installer,
metadata_version=dist.metadata_version or "",
classifiers=metadata.get_all("Classifier", []),
Expand Down

0 comments on commit 0c86e3c

Please sign in to comment.