2021-02-19 13:56:59 +01:00
|
|
|
from pip._internal.distributions.base import AbstractDistribution
|
2022-10-13 22:09:01 +02:00
|
|
|
from pip._internal.distributions.installed import InstalledDistribution
|
2020-01-21 13:18:32 +01:00
|
|
|
from pip._internal.distributions.sdist import SourceDistribution
|
2019-06-14 17:37:51 +02:00
|
|
|
from pip._internal.distributions.wheel import WheelDistribution
|
2021-02-19 13:56:59 +01:00
|
|
|
from pip._internal.req.req_install import InstallRequirement
|
2019-06-14 17:37:51 +02:00
|
|
|
|
|
|
|
|
2021-07-13 00:29:21 +02:00
|
|
|
def make_distribution_for_install_requirement(
|
|
|
|
install_req: InstallRequirement,
|
|
|
|
) -> AbstractDistribution:
|
2021-02-21 17:52:50 +01:00
|
|
|
"""Returns a Distribution for the given InstallRequirement"""
|
2022-10-13 22:09:01 +02:00
|
|
|
# Only pre-installed requirements will have a .satisfied_by dist.
|
|
|
|
if install_req.satisfied_by:
|
|
|
|
return InstalledDistribution(install_req)
|
|
|
|
|
2019-09-05 06:05:15 +02:00
|
|
|
# Editable requirements will always be source distributions. They use the
|
|
|
|
# legacy logic until we create a modern standard for them.
|
2019-06-14 17:37:51 +02:00
|
|
|
if install_req.editable:
|
|
|
|
return SourceDistribution(install_req)
|
|
|
|
|
2019-09-05 06:05:15 +02:00
|
|
|
# If it's a wheel, it's a WheelDistribution
|
2019-09-05 06:04:16 +02:00
|
|
|
if install_req.is_wheel:
|
2019-06-14 17:37:51 +02:00
|
|
|
return WheelDistribution(install_req)
|
|
|
|
|
|
|
|
# Otherwise, a SourceDistribution
|
|
|
|
return SourceDistribution(install_req)
|