|
8 | 8 | from packaging.requirements import Requirement |
9 | 9 | from packaging.utils import BuildTag, canonicalize_name |
10 | 10 |
|
11 | | -from . import overrides |
| 11 | +from . import overrides, resolver |
| 12 | +from .constraints import Constraints |
| 13 | +from .requirements_file import RequirementType |
12 | 14 |
|
13 | 15 | if typing.TYPE_CHECKING: |
14 | 16 | from . import context |
15 | 17 |
|
16 | 18 | logger = logging.getLogger(__name__) |
17 | 19 |
|
18 | 20 |
|
| 21 | +class PyPICacheProvider(resolver.PyPIProvider): |
| 22 | + """Provider for Fromager's PyPI-compatible cache server. |
| 23 | +
|
| 24 | + Wraps ``PyPIProvider`` with a simplified interface tailored for cache |
| 25 | + usage: no ``ignore_platform``, no ``override_download_url``, no |
| 26 | + ``supports_upload_time``, and ``cooldown`` is always ``None``. |
| 27 | +
|
| 28 | + ``include_wheels`` and ``include_sdists`` are mutually exclusive; |
| 29 | + exactly one must be ``True``. Defaults to wheels only. |
| 30 | +
|
| 31 | + .. caution:: |
| 32 | + Only use the ``PyPICacheProvider`` with an internal and fully-trusted |
| 33 | + cache index. Packages are not subject to cooldown or other checks. |
| 34 | + """ |
| 35 | + |
| 36 | + provider_description: typing.ClassVar[str] = ( |
| 37 | + "PyPI cache resolver (searching at {self.sdist_server_url})" |
| 38 | + ) |
| 39 | + |
| 40 | + def __init__( |
| 41 | + self, |
| 42 | + *, |
| 43 | + cache_server_url: str, |
| 44 | + include_sdists: bool = False, |
| 45 | + include_wheels: bool = True, |
| 46 | + constraints: Constraints | None = None, |
| 47 | + req_type: RequirementType | None = None, |
| 48 | + use_resolver_cache: bool = True, |
| 49 | + ): |
| 50 | + if include_sdists == include_wheels: |
| 51 | + raise ValueError( |
| 52 | + "include_sdists and include_wheels are mutually exclusive, " |
| 53 | + "exactly one must be True" |
| 54 | + ) |
| 55 | + super().__init__( |
| 56 | + include_sdists=include_sdists, |
| 57 | + include_wheels=include_wheels, |
| 58 | + sdist_server_url=cache_server_url, |
| 59 | + constraints=constraints, |
| 60 | + req_type=req_type, |
| 61 | + ignore_platform=False, |
| 62 | + use_resolver_cache=use_resolver_cache, |
| 63 | + override_download_url=None, |
| 64 | + cooldown=None, |
| 65 | + supports_upload_time=False, |
| 66 | + ) |
| 67 | + |
| 68 | + |
19 | 69 | def _dist_name_to_filename(dist_name: str) -> str: |
20 | 70 | """Transform the dist name into a prefix for a filename. |
21 | 71 |
|
|
0 commit comments