Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanups to format_control.py #6026

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/pip/_internal/models/format_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Optional, Set # noqa: F401
from typing import Optional, Set, FrozenSet # noqa: F401


class FormatControl(object):
"""A helper class for controlling formats from which packages are installed.
If a field is falsy, it isn't set. If it is {':all:'}, it should match all
packages except those listed in the other field. Only one field can be set
to {':all:'} at a time. The rest of the time exact package name matches
are listed, with any given package only showing up in one field at a time.
"""Helper for managing formats from which a package can be installed.
"""

def __init__(self, no_binary=None, only_binary=None):
# type: (Optional[Set], Optional[Set]) -> None
self.no_binary = set() if no_binary is None else no_binary
self.only_binary = set() if only_binary is None else only_binary
if no_binary is None:
no_binary = set()
if only_binary is None:
only_binary = set()

self.no_binary = no_binary
self.only_binary = only_binary

def __eq__(self, other):
return self.__dict__ == other.__dict__
Expand Down Expand Up @@ -52,6 +54,7 @@ def handle_mutual_excludes(value, target, other):
target.add(name)

def get_allowed_formats(self, canonical_name):
# type: (str) -> FrozenSet
result = {"binary", "source"}
if canonical_name in self.only_binary:
result.discard('source')
Expand All @@ -64,6 +67,7 @@ def get_allowed_formats(self, canonical_name):
return frozenset(result)

def disallow_binaries(self):
# type: () -> None
self.handle_mutual_excludes(
':all:', self.no_binary, self.only_binary,
)