Skip to content

Commit e5d17be

Browse files
committed
Add wheel support to InstallRequirement.get_dist()
Before it did support only requirements that had their metadata prepared to a local directory. WIth wheels that does not happen so we need to handle that case too. get_dist() is used by the metadata property of InstallRequirement, which in turn is useful to obtain metadata of the RequirementSet returned by the resolver.
1 parent cf3696a commit e5d17be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/pip/_internal/req/req_install.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
BaseDistribution,
2626
get_default_environment,
2727
get_directory_distribution,
28+
get_wheel_distribution,
2829
)
30+
from pip._internal.metadata.base import FilesystemWheel
2931
from pip._internal.models.link import Link
3032
from pip._internal.operations.build.metadata import generate_metadata
3133
from pip._internal.operations.build.metadata_editable import generate_editable_metadata
@@ -552,7 +554,16 @@ def metadata(self) -> Any:
552554
return self._metadata
553555

554556
def get_dist(self) -> BaseDistribution:
555-
return get_directory_distribution(self.metadata_directory)
557+
if self.metadata_directory:
558+
return get_directory_distribution(self.metadata_directory)
559+
elif self.local_file_path and self.is_wheel:
560+
return get_wheel_distribution(
561+
FilesystemWheel(self.local_file_path), canonicalize_name(self.name)
562+
)
563+
raise AssertionError(
564+
"InstallRequirement {self} has no metadata directory and no wheel: "
565+
"can't make a distribution."
566+
)
556567

557568
def assert_source_matches_version(self) -> None:
558569
assert self.source_dir

0 commit comments

Comments
 (0)