selection_prefs.py 1.9 KB

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