|
8 | 8 | InstallRequirement. |
9 | 9 | """ |
10 | 10 |
|
| 11 | +import copy |
11 | 12 | import logging |
12 | 13 | import os |
13 | 14 | import re |
@@ -385,15 +386,25 @@ def install_req_from_line( |
385 | 386 | line_source: Optional[str] = None, |
386 | 387 | user_supplied: bool = False, |
387 | 388 | config_settings: Optional[Dict[str, Union[str, List[str]]]] = None, |
| 389 | + verify_link_hash: bool = False, |
388 | 390 | ) -> InstallRequirement: |
389 | 391 | """Creates an InstallRequirement from a name, which might be a |
390 | 392 | requirement, directory containing 'setup.py', filename, or URL. |
391 | 393 |
|
392 | 394 | :param line_source: An optional string describing where the line is from, |
393 | 395 | for logging purposes in case of an error. |
| 396 | + :param verify_link_hash: If True, consider the downloaded resource has to be |
| 397 | + hash checked against the hash that was provided in the URL, in addition to |
| 398 | + the hashes provided via hash_options. |
394 | 399 | """ |
395 | 400 | parts = parse_req_from_line(name, line_source) |
396 | 401 |
|
| 402 | + # |
| 403 | + if parts.link and parts.link.hash and verify_link_hash: |
| 404 | + assert parts.link.hash_name |
| 405 | + hash_options = copy.deepcopy(hash_options) or {} |
| 406 | + hash_options.setdefault(parts.link.hash_name, []).append(parts.link.hash) |
| 407 | + |
397 | 408 | return InstallRequirement( |
398 | 409 | parts.requirement, |
399 | 410 | comes_from, |
@@ -483,6 +494,7 @@ def install_req_from_parsed_requirement( |
483 | 494 | constraint=parsed_req.constraint, |
484 | 495 | line_source=parsed_req.line_source, |
485 | 496 | user_supplied=user_supplied, |
| 497 | + verify_link_hash=True, |
486 | 498 | ) |
487 | 499 | return req |
488 | 500 |
|
|
0 commit comments