selection_prefs.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from __future__ import annotations
  2. from pip._internal.models.format_control import FormatControl
  3. from pip._internal.models.release_control import ReleaseControl
  4. # TODO: This needs Python 3.10's improved slots support for dataclasses
  5. # to be converted into a dataclass.
  6. class SelectionPreferences:
  7. """
  8. Encapsulates the candidate selection preferences for downloading
  9. and installing files.
  10. """
  11. __slots__ = [
  12. "allow_yanked",
  13. "release_control",
  14. "format_control",
  15. "prefer_binary",
  16. "ignore_requires_python",
  17. ]
  18. # Don't include an allow_yanked default value to make sure each call
  19. # site considers whether yanked releases are allowed. This also causes
  20. # that decision to be made explicit in the calling code, which helps
  21. # people when reading the code.
  22. def __init__(
  23. self,
  24. allow_yanked: bool,
  25. release_control: ReleaseControl | None = None,
  26. format_control: FormatControl | None = None,
  27. prefer_binary: bool = False,
  28. ignore_requires_python: bool | None = None,
  29. ) -> None:
  30. """Create a SelectionPreferences object.
  31. :param allow_yanked: Whether files marked as yanked (in the sense
  32. of PEP 592) are permitted to be candidates for install.
  33. :param release_control: A ReleaseControl object or None. Used to control
  34. whether pre-releases are allowed for specific packages.
  35. :param format_control: A FormatControl object or None. Used to control
  36. the selection of source packages / binary packages when consulting
  37. the index and links.
  38. :param prefer_binary: Whether to prefer an old, but valid, binary
  39. dist over a new source dist.
  40. :param ignore_requires_python: Whether to ignore incompatible
  41. "Requires-Python" values in links. Defaults to False.
  42. """
  43. if ignore_requires_python is None:
  44. ignore_requires_python = False
  45. self.allow_yanked = allow_yanked
  46. self.release_control = release_control
  47. self.format_control = format_control
  48. self.prefer_binary = prefer_binary
  49. self.ignore_requires_python = ignore_requires_python