|
7 | 7 | import shlex
|
8 | 8 | import typing
|
9 | 9 | from typing import (
|
| 10 | + Any, |
10 | 11 | Callable,
|
11 | 12 | Dict,
|
12 | 13 | Iterable,
|
@@ -457,26 +458,41 @@ def strip_extras(name: str) -> str:
|
457 | 458 | return re.sub(_strip_extras_re, "", name)
|
458 | 459 |
|
459 | 460 |
|
460 |
| -def copy_install_requirement(template: InstallRequirement) -> InstallRequirement: |
461 |
| - """Make a copy of an ``InstallRequirement``.""" |
462 |
| - ireq = InstallRequirement( |
463 |
| - req=copy.deepcopy(template.req), |
464 |
| - comes_from=template.comes_from, |
465 |
| - editable=template.editable, |
466 |
| - link=template.link, |
467 |
| - markers=template.markers, |
468 |
| - use_pep517=template.use_pep517, |
469 |
| - isolated=template.isolated, |
470 |
| - install_options=template.install_options, |
471 |
| - global_options=template.global_options, |
472 |
| - hash_options=template.hash_options, |
473 |
| - constraint=template.constraint, |
474 |
| - extras=template.extras, |
475 |
| - user_supplied=template.user_supplied, |
476 |
| - ) |
| 461 | +def copy_install_requirement( |
| 462 | + template: InstallRequirement, **extra_kwargs: Any |
| 463 | +) -> InstallRequirement: |
| 464 | + """Make a copy of a template ``InstallRequirement`` with extra kwargs.""" |
| 465 | + # Prepare install requirement kwargs. |
| 466 | + kwargs = { |
| 467 | + "comes_from": template.comes_from, |
| 468 | + "editable": template.editable, |
| 469 | + "link": template.link, |
| 470 | + "markers": template.markers, |
| 471 | + "use_pep517": template.use_pep517, |
| 472 | + "isolated": template.isolated, |
| 473 | + "install_options": template.install_options, |
| 474 | + "global_options": template.global_options, |
| 475 | + "hash_options": template.hash_options, |
| 476 | + "constraint": template.constraint, |
| 477 | + "extras": template.extras, |
| 478 | + "user_supplied": template.user_supplied, |
| 479 | + } |
| 480 | + kwargs.update(extra_kwargs) |
| 481 | + |
| 482 | + # Original link does not belong to install requirements constructor, |
| 483 | + # pop it now to update later. |
| 484 | + original_link = kwargs.pop("original_link", None) |
| 485 | + |
| 486 | + # Copy template.req if not specified in extra kwargs. |
| 487 | + if "req" not in kwargs: |
| 488 | + kwargs["req"] = copy.deepcopy(template.req) |
| 489 | + |
| 490 | + ireq = InstallRequirement(**kwargs) |
477 | 491 |
|
478 | 492 | # If the original_link was None, keep it so. Passing `link` as an
|
479 |
| - # argument to `InstallRequirement` sets it as the original_link: |
480 |
| - ireq.original_link = template.original_link |
| 493 | + # argument to `InstallRequirement` sets it as the original_link. |
| 494 | + ireq.original_link = ( |
| 495 | + template.original_link if original_link is None else original_link |
| 496 | + ) |
481 | 497 |
|
482 | 498 | return ireq
|
0 commit comments