python (3.11.7)

(root)/
lib/
python3.11/
site-packages/
pip/
_internal/
resolution/
resolvelib/
base.py
       1  from typing import FrozenSet, Iterable, Optional, Tuple, Union
       2  
       3  from pip._vendor.packaging.specifiers import SpecifierSet
       4  from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
       5  from pip._vendor.packaging.version import LegacyVersion, Version
       6  
       7  from pip._internal.models.link import Link, links_equivalent
       8  from pip._internal.req.req_install import InstallRequirement
       9  from pip._internal.utils.hashes import Hashes
      10  
      11  CandidateLookup = Tuple[Optional["Candidate"], Optional[InstallRequirement]]
      12  CandidateVersion = Union[LegacyVersion, Version]
      13  
      14  
      15  def format_name(project: str, extras: FrozenSet[str]) -> str:
      16      if not extras:
      17          return project
      18      canonical_extras = sorted(canonicalize_name(e) for e in extras)
      19      return "{}[{}]".format(project, ",".join(canonical_extras))
      20  
      21  
      22  class ESC[4;38;5;81mConstraint:
      23      def __init__(
      24          self, specifier: SpecifierSet, hashes: Hashes, links: FrozenSet[Link]
      25      ) -> None:
      26          self.specifier = specifier
      27          self.hashes = hashes
      28          self.links = links
      29  
      30      @classmethod
      31      def empty(cls) -> "Constraint":
      32          return Constraint(SpecifierSet(), Hashes(), frozenset())
      33  
      34      @classmethod
      35      def from_ireq(cls, ireq: InstallRequirement) -> "Constraint":
      36          links = frozenset([ireq.link]) if ireq.link else frozenset()
      37          return Constraint(ireq.specifier, ireq.hashes(trust_internet=False), links)
      38  
      39      def __bool__(self) -> bool:
      40          return bool(self.specifier) or bool(self.hashes) or bool(self.links)
      41  
      42      def __and__(self, other: InstallRequirement) -> "Constraint":
      43          if not isinstance(other, InstallRequirement):
      44              return NotImplemented
      45          specifier = self.specifier & other.specifier
      46          hashes = self.hashes & other.hashes(trust_internet=False)
      47          links = self.links
      48          if other.link:
      49              links = links.union([other.link])
      50          return Constraint(specifier, hashes, links)
      51  
      52      def is_satisfied_by(self, candidate: "Candidate") -> bool:
      53          # Reject if there are any mismatched URL constraints on this package.
      54          if self.links and not all(_match_link(link, candidate) for link in self.links):
      55              return False
      56          # We can safely always allow prereleases here since PackageFinder
      57          # already implements the prerelease logic, and would have filtered out
      58          # prerelease candidates if the user does not expect them.
      59          return self.specifier.contains(candidate.version, prereleases=True)
      60  
      61  
      62  class ESC[4;38;5;81mRequirement:
      63      @property
      64      def project_name(self) -> NormalizedName:
      65          """The "project name" of a requirement.
      66  
      67          This is different from ``name`` if this requirement contains extras,
      68          in which case ``name`` would contain the ``[...]`` part, while this
      69          refers to the name of the project.
      70          """
      71          raise NotImplementedError("Subclass should override")
      72  
      73      @property
      74      def name(self) -> str:
      75          """The name identifying this requirement in the resolver.
      76  
      77          This is different from ``project_name`` if this requirement contains
      78          extras, where ``project_name`` would not contain the ``[...]`` part.
      79          """
      80          raise NotImplementedError("Subclass should override")
      81  
      82      def is_satisfied_by(self, candidate: "Candidate") -> bool:
      83          return False
      84  
      85      def get_candidate_lookup(self) -> CandidateLookup:
      86          raise NotImplementedError("Subclass should override")
      87  
      88      def format_for_error(self) -> str:
      89          raise NotImplementedError("Subclass should override")
      90  
      91  
      92  def _match_link(link: Link, candidate: "Candidate") -> bool:
      93      if candidate.source_link:
      94          return links_equivalent(link, candidate.source_link)
      95      return False
      96  
      97  
      98  class ESC[4;38;5;81mCandidate:
      99      @property
     100      def project_name(self) -> NormalizedName:
     101          """The "project name" of the candidate.
     102  
     103          This is different from ``name`` if this candidate contains extras,
     104          in which case ``name`` would contain the ``[...]`` part, while this
     105          refers to the name of the project.
     106          """
     107          raise NotImplementedError("Override in subclass")
     108  
     109      @property
     110      def name(self) -> str:
     111          """The name identifying this candidate in the resolver.
     112  
     113          This is different from ``project_name`` if this candidate contains
     114          extras, where ``project_name`` would not contain the ``[...]`` part.
     115          """
     116          raise NotImplementedError("Override in subclass")
     117  
     118      @property
     119      def version(self) -> CandidateVersion:
     120          raise NotImplementedError("Override in subclass")
     121  
     122      @property
     123      def is_installed(self) -> bool:
     124          raise NotImplementedError("Override in subclass")
     125  
     126      @property
     127      def is_editable(self) -> bool:
     128          raise NotImplementedError("Override in subclass")
     129  
     130      @property
     131      def source_link(self) -> Optional[Link]:
     132          raise NotImplementedError("Override in subclass")
     133  
     134      def iter_dependencies(self, with_requires: bool) -> Iterable[Optional[Requirement]]:
     135          raise NotImplementedError("Override in subclass")
     136  
     137      def get_install_requirement(self) -> Optional[InstallRequirement]:
     138          raise NotImplementedError("Override in subclass")
     139  
     140      def format_for_error(self) -> str:
     141          raise NotImplementedError("Subclass should override")