selection_prefs.py 2.0 KB

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