Skip to content

Commit

Permalink
Add wheel support in InstarallRequirement.get_dist()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbidoul committed May 7, 2022
1 parent cf3696a commit e2c4596
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -552,7 +554,16 @@ 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(
"InstallRequirement {self} has no metadata directory and no wheel: "
"can't make a distribution."
)

def assert_source_matches_version(self) -> None:
assert self.source_dir
Expand Down

0 comments on commit e2c4596

Please sign in to comment.