|
25 | 25 | )
|
26 | 26 | from pip._internal.index.package_finder import PackageFinder
|
27 | 27 | from pip._internal.metadata import BaseDistribution
|
| 28 | +from pip._internal.models.direct_url import ArchiveInfo |
28 | 29 | from pip._internal.models.link import Link
|
29 | 30 | from pip._internal.models.wheel import Wheel
|
30 | 31 | from pip._internal.network.download import BatchDownloader, Downloader
|
|
35 | 36 | from pip._internal.network.session import PipSession
|
36 | 37 | from pip._internal.operations.build.build_tracker import BuildTracker
|
37 | 38 | from pip._internal.req.req_install import InstallRequirement
|
| 39 | +from pip._internal.utils.direct_url_helpers import ( |
| 40 | + direct_url_for_editable, |
| 41 | + direct_url_from_link, |
| 42 | +) |
38 | 43 | from pip._internal.utils.hashes import Hashes, MissingHashes
|
39 | 44 | from pip._internal.utils.logging import indent_log
|
40 |
| -from pip._internal.utils.misc import display_path, hide_url, is_installable_dir |
| 45 | +from pip._internal.utils.misc import ( |
| 46 | + display_path, |
| 47 | + hash_file, |
| 48 | + hide_url, |
| 49 | + is_installable_dir, |
| 50 | +) |
41 | 51 | from pip._internal.utils.temp_dir import TempDirectory
|
42 | 52 | from pip._internal.utils.unpacking import unpack_file
|
43 | 53 | from pip._internal.vcs import vcs
|
@@ -489,6 +499,23 @@ def _prepare_linked_requirement(
|
489 | 499 | hashes.check_against_path(file_path)
|
490 | 500 | local_file = File(file_path, content_type=None)
|
491 | 501 |
|
| 502 | + # If download_info is set, we got it from the wheel cache. |
| 503 | + if req.download_info is None: |
| 504 | + # Editables don't go through this function (see |
| 505 | + # prepare_editable_requirement). |
| 506 | + assert not req.editable |
| 507 | + req.download_info = direct_url_from_link(link, req.source_dir) |
| 508 | + # Make sure we have a hash in download_info. If we got it as part of the |
| 509 | + # URL, it will have been verified and we can rely on it. Otherwise we |
| 510 | + # compute it from the downloaded file. |
| 511 | + if ( |
| 512 | + isinstance(req.download_info.info, ArchiveInfo) |
| 513 | + and not req.download_info.info.hash |
| 514 | + and local_file |
| 515 | + ): |
| 516 | + hash = hash_file(local_file.path)[0].hexdigest() |
| 517 | + req.download_info.info.hash = f"sha256={hash}" |
| 518 | + |
492 | 519 | # For use in later processing,
|
493 | 520 | # preserve the file path on the requirement.
|
494 | 521 | if local_file:
|
@@ -547,6 +574,8 @@ def prepare_editable_requirement(
|
547 | 574 | )
|
548 | 575 | req.ensure_has_source_dir(self.src_dir)
|
549 | 576 | req.update_editable()
|
| 577 | + assert req.source_dir |
| 578 | + req.download_info = direct_url_for_editable(req.unpacked_source_directory) |
550 | 579 |
|
551 | 580 | dist = _get_prepared_distribution(
|
552 | 581 | req,
|
|
0 commit comments