Skip to content

Commit

Permalink
Merge pull request #6026 from pradyunsg/format-control-cleanups
Browse files Browse the repository at this point in the history
Minor cleanups to format_control.py
  • Loading branch information
pradyunsg committed Nov 21, 2018
2 parents 93d8f17 + ad70174 commit 74c09b8
Showing 1 changed file with 12 additions and 8 deletions.
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,
)

0 comments on commit 74c09b8

Please sign in to comment.