From 2922e34f72bf225eb7feb91d96b151029fd818b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 8 Jan 2022 13:10:03 +0100 Subject: [PATCH] Add wheel support to InstallRequirement.get_dist --- src/pip/_internal/req/req_install.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 6fa6eb2a2a9..3e0f126533b 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -25,7 +25,9 @@ BaseDistribution, get_default_environment, get_directory_distribution, + get_wheel_distribution, ) +from pip._internal.metadata.base import FilesystemWheel from pip._internal.models.link import Link from pip._internal.operations.build.metadata import generate_metadata from pip._internal.operations.build.metadata_editable import generate_editable_metadata @@ -547,7 +549,15 @@ def metadata(self) -> Any: return self._metadata def get_dist(self) -> BaseDistribution: - return get_directory_distribution(self.metadata_directory) + if self.metadata_directory: + return get_directory_distribution(self.metadata_directory) + elif self.local_file_path and self.is_wheel: + return get_wheel_distribution( + FilesystemWheel(self.local_file_path), canonicalize_name(self.name) + ) + raise AssertionError( + "No metadata directory and no wheel: can't make a distribution." + ) def assert_source_matches_version(self) -> None: assert self.source_dir