Skip to content

Commit 4c33131

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 c7d5dda commit 4c33131

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/pip/_internal/req/req_install.py

Lines changed: 12 additions & 1 deletion
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
@@ -553,7 +555,16 @@ def metadata(self) -> Any:
553555
return self._metadata
554556

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

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

0 commit comments

Comments
 (0)