From 7cdc1aaa3a96e5d58e566edb76ab51d8e64bce0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 30 May 2022 10:22:39 +0200 Subject: [PATCH] Use metadata['name'] to get requirement name Co-authored-by: Tzu-ping Chung --- src/pip/_internal/commands/install.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 4e63df1bb4f..191239750eb 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -354,14 +354,15 @@ def run(self, options: Values, args: List[str]) -> int: ) if options.dry_run: - items = [ - f"{item.name}-{item.metadata['version']}" - for item in sorted( - requirement_set.all_requirements, key=lambda x: str(x.name) + would_install_items = sorted( + (r.metadata["name"], r.metadata["version"]) + for r in requirement_set.all_requirements + ) + if would_install_items: + write_output( + "Would install %s", + " ".join("-".join(item) for item in would_install_items), ) - ] - if items: - write_output("Would install %s", " ".join(items)) return SUCCESS try: