selection_prefs.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # 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, # type: bool
  17. allow_all_prereleases=False, # type: bool
  18. format_control=None, # type: Optional[FormatControl]
  19. prefer_binary=False, # type: bool
  20. ignore_requires_python=None, # type: Optional[bool]
  21. ):
  22. # type: (...) -> None
  23. """Create a SelectionPreferences object.
  24. :param allow_yanked: Whether files marked as yanked (in the sense
  25. of PEP 592) are permitted to be candidates for install.
  26. :param format_control: A FormatControl object or None. Used to control
  27. the selection of source packages / binary packages when consulting
  28. the index and links.
  29. :param prefer_binary: Whether to prefer an old, but valid, binary
  30. dist over a new source dist.
  31. :param ignore_requires_python: Whether to ignore incompatible
  32. "Requires-Python" values in links. Defaults to False.
  33. """
  34. if ignore_requires_python is None:
  35. ignore_requires_python = False
  36. self.allow_yanked = allow_yanked
  37. self.allow_all_prereleases = allow_all_prereleases
  38. self.format_control = format_control
  39. self.prefer_binary = prefer_binary
  40. self.ignore_requires_python = ignore_requires_python