selection_prefs.py 2.0 KB

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