1from __future__ import annotations 2 3from typing import TYPE_CHECKING, List 4 5from pdm import termui 6 7if TYPE_CHECKING: 8 from pdm.models.candidates import Candidate 9 10 11class PdmException(Exception): 12 pass 13 14 15class PdmUsageError(PdmException): 16 pass 17 18 19class RequirementError(PdmException, ValueError): 20 pass 21 22 23class InvalidPyVersion(PdmException, ValueError): 24 pass 25 26 27class CorruptedCacheError(PdmException): 28 pass 29 30 31class CandidateNotFound(PdmException): 32 pass 33 34 35class CandidateInfoNotFound(PdmException): 36 def __init__(self, candidate: Candidate) -> None: 37 message = ( 38 "No metadata information is available for " 39 f"{termui.green(str(candidate))}." 40 ) 41 self.candidate = candidate 42 super().__init__(message) 43 44 45class ExtrasError(UserWarning): 46 def __init__(self, extras: List[str]) -> None: 47 super().__init__() 48 self.extras = tuple(extras) 49 50 def __str__(self) -> str: 51 return f"Extras not found: {self.extras}" 52 53 54class ProjectError(PdmUsageError): 55 pass 56 57 58class InstallationError(PdmException): 59 pass 60 61 62class UninstallError(PdmException): 63 pass 64 65 66class NoConfigError(PdmException, KeyError): 67 def __init__(self, key: str) -> None: 68 super().__init__("No such config item: {}".format(key)) 69 70 71class NoPythonVersion(PdmException): 72 pass 73 74 75class BuildError(PdmException, RuntimeError): 76 pass 77