|
15 | 15 | from itertools import chain, groupby, repeat |
16 | 16 | from typing import TYPE_CHECKING, Dict, Iterator, List, Literal, Optional, Union |
17 | 17 |
|
| 18 | +from pipenv.patched.pip._vendor.packaging.requirements import InvalidRequirement |
| 19 | +from pipenv.patched.pip._vendor.packaging.version import InvalidVersion |
18 | 20 | from pipenv.patched.pip._vendor.rich.console import Console, ConsoleOptions, RenderResult |
19 | 21 | from pipenv.patched.pip._vendor.rich.markup import escape |
20 | 22 | from pipenv.patched.pip._vendor.rich.text import Text |
@@ -429,7 +431,7 @@ class HashErrors(InstallationError): |
429 | 431 | """Multiple HashError instances rolled into one for reporting""" |
430 | 432 |
|
431 | 433 | def __init__(self) -> None: |
432 | | - self.errors: List["HashError"] = [] |
| 434 | + self.errors: List[HashError] = [] |
433 | 435 |
|
434 | 436 | def append(self, error: "HashError") -> None: |
435 | 437 | self.errors.append(error) |
@@ -775,3 +777,33 @@ def __init__(self, *, distribution: "BaseDistribution") -> None: |
775 | 777 | ), |
776 | 778 | hint_stmt=None, |
777 | 779 | ) |
| 780 | + |
| 781 | + |
| 782 | +class InvalidInstalledPackage(DiagnosticPipError): |
| 783 | + reference = "invalid-installed-package" |
| 784 | + |
| 785 | + def __init__( |
| 786 | + self, |
| 787 | + *, |
| 788 | + dist: "BaseDistribution", |
| 789 | + invalid_exc: Union[InvalidRequirement, InvalidVersion], |
| 790 | + ) -> None: |
| 791 | + installed_location = dist.installed_location |
| 792 | + |
| 793 | + if isinstance(invalid_exc, InvalidRequirement): |
| 794 | + invalid_type = "requirement" |
| 795 | + else: |
| 796 | + invalid_type = "version" |
| 797 | + |
| 798 | + super().__init__( |
| 799 | + message=Text( |
| 800 | + f"Cannot process installed package {dist} " |
| 801 | + + (f"in {installed_location!r} " if installed_location else "") |
| 802 | + + f"because it has an invalid {invalid_type}:\n{invalid_exc.args[0]}" |
| 803 | + ), |
| 804 | + context=( |
| 805 | + "Starting with pip 24.1, packages with invalid " |
| 806 | + f"{invalid_type}s can not be processed." |
| 807 | + ), |
| 808 | + hint_stmt="To proceed this package must be uninstalled.", |
| 809 | + ) |
0 commit comments