selection_prefs.py 1.8 KB

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