| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import optparse |
| 4 |
from abc import ABCMeta, abstractmethod |
| 5 |
from contextlib import contextmanager |
| 6 |
from typing import Iterator |
| 7 |
|
| 8 |
from pip._internal.commands.install import InstallCommand |
| 9 |
from pip._internal.index.package_finder import PackageFinder |
| 10 |
from pip._internal.models.index import PyPI |
| 11 |
from pip._internal.network.session import PipSession |
| 12 |
from pip._internal.req import InstallRequirement |
| 13 |
|
| 14 |
|
| 15 |
class BaseRepository(metaclass=ABCMeta): |
| 16 |
DEFAULT_INDEX_URL = PyPI.simple_url |
| 17 |
|
| 18 |
def clear_caches(self) -> None: |
| 19 |
"""Should clear any caches used by the implementation.""" |
| 20 |
|
| 21 |
@abstractmethod |
| 22 |
def find_best_match( |
| 23 |
self, ireq: InstallRequirement, prereleases: bool | None |
| 24 |
) -> InstallRequirement: |
| 25 |
""" |
| 26 |
Returns a pinned InstallRequirement object that indicates the best match |
| 27 |
for the given InstallRequirement according to the external repository. |
| 28 |
""" |
| 29 |
|
| 30 |
@abstractmethod |
| 31 |
def get_dependencies(self, ireq: InstallRequirement) -> set[InstallRequirement]: |
| 32 |
""" |
| 33 |
Given a pinned, URL, or editable InstallRequirement, returns a set of |
| 34 |
dependencies (also InstallRequirements, but not necessarily pinned). |
| 35 |
They indicate the secondary dependencies for the given requirement. |
| 36 |
""" |
| 37 |
|
| 38 |
@abstractmethod |
| 39 |
def get_hashes(self, ireq: InstallRequirement) -> set[str]: |
| 40 |
""" |
| 41 |
Given a pinned InstallRequirement, returns a set of hashes that represent |
| 42 |
all of the files for a given requirement. It is not acceptable for an |
| 43 |
editable or unpinned requirement to be passed to this function. |
| 44 |
""" |
| 45 |
|
| 46 |
@abstractmethod |
| 47 |
@contextmanager |
| 48 |
def allow_all_wheels(self) -> Iterator[None]: |
| 49 |
""" |
| 50 |
Monkey patches pip.Wheel to allow wheels from all platforms and Python versions. |
| 51 |
""" |
| 52 |
|
| 53 |
@property |
| 54 |
@abstractmethod |
| 55 |
def options(self) -> optparse.Values: |
| 56 |
"""Returns parsed pip options""" |
| 57 |
|
| 58 |
@property |
| 59 |
@abstractmethod |
| 60 |
def session(self) -> PipSession: |
| 61 |
"""Returns a session to make requests""" |
| 62 |
|
| 63 |
@property |
| 64 |
@abstractmethod |
| 65 |
def finder(self) -> PackageFinder: |
| 66 |
"""Returns a package finder to interact with simple repository API (PEP 503)""" |
| 67 |
|
| 68 |
@property |
| 69 |
@abstractmethod |
| 70 |
def command(self) -> InstallCommand: |
| 71 |
"""Return an install command.""" |